数组的集合操作:
>>> 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‘)
原文地址:https://www.cnblogs.com/nzyjlr/p/10341724.html
时间: 2024-11-05 19:45:00