Python | numpy.isin () method

Using the numpy.isin() method, we see that one array that has values ​​is checked in another numpy array that has 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 with numpy .isin () we can get a boolean array if the elements are matched to the target array.

# NumPy import

import numpy as np

  
# using the numpy.isin () method

gfg1 = np.array ([ 1 , 2 , 3 , 4 , 5 ])

lis = [ 1 , 3 , 5 ]

gfg = np.isin (gfg1, lis)

 

print (gfg)

Exit:

[True False True False True]

Example # 2:

# NumPy import

import numpy as np

 
# using the numpy.isin () method

gfg1 = np.array ([[ 1 , 3 ], [ 5 , 7 ], [ 9 , 11 ]])

lis = [ 1 , 3 , 11 , 9 ]

gfg = np.isin (gfg1, lis)

 

print (gfg)

Quit:

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