6. 数组的集合函数
>>> s1 = {10,20,30,40}
>>> s2 = {10,100,20,200}
>>> s1&s2
{10, 20}
>>> s1|s2
{100, 40, 200, 10, 20, 30}
>>> arr1 = np.array([4,1, 1, 2, 2, 3, 3])
>>> np.unique(arr1)
[1 2 3 4]
>>> a = np.array([[1, 1], [2, 3]])
>>> np.unique(a)
[1 2 3]
>>> arr3 = np.array([100,10,10,10,20,30,40,50,1])
>>> np.unique(arr3)
[ 1 10 20 30 40 50 100]
>>> arr1 = np.arange(10,20)
>>> np.intersect1d(arr1,arr3)
[10]
>>> np.union1d(arr1,arr2)
[ 0 1 2 3 4 10 11 12 13 14 15 16 17 18 19]
>>> np.setdiff1d(arr1,arr2)
[10 11 12 13 14 15 16 17 18 19]
>>> np.setdiff1d(arr2,arr1)
[0 1 2 3 4]
>>> np.setxor1d(arr1,arr3)
[ 1 11 12 13 14 15 16 17 18 19 20 30 40 50 100]
>>> np.in1d(arr1,arr2)
[False False False False False False False False False False]
>>> np.in1d(arr1,arr3)
[ True False False False False False False False False False]