I have two lists. I want to find the indices of the elements in the big list which are not present in the small list. How can I use the *isin()* function for it?

+2 votes

Best answer

You can use the negation of the* isin()* function to select the indices of elements in the big list that are not present in the smaller list.

Here is an example. 'a' is the big list, and 'b' is the smaller list.

>>> import numpy as np

>>> a=np.array([11,12,13,14,15,16,17])

>>> b=np.array([12,14,15,17])>>> (~np.isin(a, b)).nonzero()[0]

array([0, 2, 5])