Python中的 numpy.setxor1d()函数
numpy.setxor1d()
函数找到两个数组的异或集,并返回仅在一个(不是两个)输入数组中的排序后的唯一值。
Syntax : numpy.setxor1d(arr1, arr2, assume_unique = False)
Parameters :
arr1, arr2 : [array_like] Input arrays.
assume_unique : [bool] If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False.
Return : [ndarray] Sorted 1D array of unique values that are in only one of the input arrays.
代码#1:
# Python program explaining
# numpy.setxor1d() function
# importing numpy as geek
import numpy as geek
arr1 = [1, 2, 3, 4]
arr2 = [2, 4, 6, 8]
gfg = geek.setxor1d(arr1, arr2)
print (gfg)
输出 :
[1 3 6 8]
代码#2:
# Python program explaining
# numpy.setxor1d() function
# importing numpy as geek
import numpy as geek
arr1 = [1, 2, 3, 4, 5]
arr2 = [-2, -1, 0, 1, 2]
gfg = geek.setxor1d(arr1, arr2)
print (gfg)
输出 :
[-2 -1 0 3 4 5]