numpy.isin() method - Python

Last Updated : 20 Mar, 2026

The numpy.isin() method provides a way to check whether elements of one NumPy array exist in another array and returns a boolean array indicating which elements are present.

An example to see if a single element exists in a list.

Python
import numpy as np
a = [5, 10, 15, 20]
res = np.isin(10, a)  
print(res)

Output
True

Explanation: The element 10 is present in the list[5, 10, 15, 20] so the output is True.

Syntax

numpy.isin(element, test_elements, assume_unique=False, invert=False)

Parameters:

  • element: Input array whose values are checked.
  • test_elements: values to check against (array-like such as list, tuple or NumPy array).
  • assume_unique: If True, function assumes both arrays contain unique elements (for faster computation). Default is False.
  • invert: If True, returns True for elements not in test_elements. Default is False.

Return Value: A boolean array of same shape as element, indicating True where element is in test_elements.

Examples

Example 1: Here we check which elements of a 1-D array exist in a given list.

Python
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
li = [1, 3, 5]
res = np.isin(arr, li)
print(res)

Output
[ True False  True False  True]

Explanation:

  • Element 1 -> present -> True
  • Element 2 -> not present -> False
  • Element 3 -> present -> True
  • Element 4 -> not present -> False
  • Element 5 -> present -> True

Example 2: This code check whether a single element exists in a tuple using numpy.isin().

Python
import numpy as np
t = (8, 12, 16, 24)
res = np.isin(16, t)
print(res)

Output
True

Explanation: element 16 is present in the tuple (8, 12, 16, 24), so the function returns True.

Example 3: This example checks which elements of a 2-D array are present in a list of values.

Python
import numpy as np
arr = np.array([[1, 3], [5, 7], [9, 11]])
li = [1, 3, 11, 9]
res = np.isin(arr, li)
print(res)

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

Explanation:

  • Row 0 -> [1, 3] -> both in list -> [True, True]
  • Row 1 -> [5, 7] -> neither in list -> [False, False]
  • Row 2 -> [9, 11] -> both in list -> [True, True]

Example 4: We can also find elements not present in the reference list using invert=True.

Python
import numpy as np
arr = np.array([10, 20, 30, 40])
li = [20, 40, 50]
res = np.isin(arr, li, invert=True)
print(res)

Output
[ True False  True False]

Explanation:

  • Element 10 -> not in li -> True
  • Element 20 -> in li -> False
  • Element 30 -> not in li -> True
  • Element 40 -> in li -> False
Comment