It's pretty simple, use numpy.intersect1d to calculate the elements shared between a and b , then check which of these elements are not in a using numpy.in1d and finally get their position in the array using numpy.argwhere .
>>> import numpy as np >>> a, b = np.array([13., 14., 15., 32., 33.]), np.array([15., 16., 17., 33., 34., 47.]) >>> np.argwhere(np.in1d(a, np.intersect1d(a,b)) == False) array([[0], [1], [3]])
If you prefer a list, just add .flatten to convert the matrix to a vector, and then apply .tolist to get the list:
>>> np.argwhere(np.in1d(a, np.intersect1d(a,b)) == False).flatten().tolist() [0, 1, 3]
source share