1. 程式人生 > >Numpy - 數組的集合操作

Numpy - 數組的集合操作

png arr .com alt intersect nan pre span type

數組的集合操作:

技術分享圖片

>>> x=np.array([cherry,apple,pear,banana,cherry])
>>> y=np.array([cherry,pear,strawberry,orange,cherry])
>>> np.unique(x)
array([apple, banana, cherry, pear], dtype=<U6)
>>> np.intersect1d(x,y)
array([cherry
, pear], dtype=<U10) >>> np.union1d(x,y) array([apple, banana, cherry, orange, pear, strawberry], dtype=<U10) >>> np.in1d(x,y) array([ True, False, True, False, True]) >>> np.setdiff1d(x,y) array([apple, banana], dtype=<U6) >>> np.setxor1d(x,y) array([
apple, banana, orange, strawberry], dtype=<U10)

Numpy - 數組的集合操作