To obtain only the values in the first set that are not present in the second set, use the setdiff1d() method.
Calculate the difference of set1 from set2.
import numpy as np set1 = np.array([1, 2, 3, 4]) set2 = np.array([3, 4, 5, 6]) newarr = np.setdiff1d(set1, set2, assume_unique=True) print(newarr) |
To retrieve only the values that are not present in both sets, use the setxor1d() method.
Calculate the symmetric difference between set1 and set2.
import numpy as np set1 = np.array([1, 2, 3, 4]) set2 = np.array([3, 4, 5, 6]) newarr = np.setxor1d(set1, set2, assume_unique=True) print(newarr) |