Numpy - 數組的集合操作
阿新 • • 發佈:2019-01-31
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 - 數組的集合操作