Determine arguments where two numpy arrays intersect in Python -
i have 2 arrays, say:
a, b = np.array([13., 14., 15., 32., 33.]), np.array([15., 16., 17., 33., 34., 47.])
i need find indices of elements in not present in b. in above example result be:
[0, 1, 3]
because a[0], a[1] , a[3] 13., 14. , 32., not present in b. notice don't care know actual values of 13., 14. , 32. (i have used set(a).difference(set(b)), in case). genuinely interested in indices only.
if possible answer should "vectorized", i.e. not using loop.
you use np.in1d:
>>> np.arange(a.shape[0])[~np.in1d(a,b)].tolist() [0, 1, 3]
Comments
Post a Comment