Python | numpy.isin() method

With the help of numpy.isin() method, we can see that one array having values are checked in a different numpy array having different elements with different sizes.

Syntax : numpy.isin(target_array, list)

Return : Return boolean array having same size as of target_array.

Example #1 :

In this example we can see that by using numpy.isin() method, we are able to get the boolean array if elements are matched with the target array.



filter_none

edit
close

play_arrow

link
brightness_4
code

# import numpy
import numpy as np
  
# using numpy.isin() method
gfg1 = np.array([1, 2, 3, 4, 5])
lis = [1, 3, 5]
gfg = np.isin(gfg1, lis)
  
print(gfg)

chevron_right


Output :

[ True False True False True]

Example #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# import numpy
import numpy as np
  
# using numpy.isin() method
gfg1 = np.array([[1, 3], [5, 7], [9, 11]])
lis = [1, 3, 11, 9]
gfg = np.isin(gfg1, lis)
  
print(gfg)

chevron_right


Output :

[[ True True]
[False False]
[ True True]]

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.