+1 vote
in Programming Languages by (74.2k points)

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?

1 Answer

+2 votes
by (351k points)
selected by
 
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])


...