isin#

ivy.isin(elements, test_elements, /, *, assume_unique=False, invert=False)[source]#

Test if each element of elements is in test_elements.

Parameters:
  • elements (Union[Array, NativeArray]) – input array

  • test_elements (Union[Array, NativeArray]) – values against which to test for each input element

  • assume_unique (bool, default: False) – If True, assumes both elements and test_elements contain unique elements, which can speed up the calculation. Default value is False.

  • invert (bool, default: False) – If True, inverts the boolean return array, resulting in True values for elements not in test_elements. Default value is False.

Return type:

Array

Returns:

ret – output a boolean array of the same shape as elements that is True for elements in test_elements and False otherwise.

Examples

>>> x = ivy.array([[10, 7, 4], [3, 2, 1]])
>>> y = ivy.array([1, 2, 3])
>>> ivy.isin(x, y)
ivy.array([[False, False, False], [ True,  True,  True]])
>>> x = ivy.array([3, 2, 1, 0])
>>> y = ivy.array([1, 2, 3])
>>> ivy.isin(x, y, invert=True)
ivy.array([False, False, False,  True])
Array.isin(self, test_elements, /, *, assume_unique=False, invert=False)[source]#

ivy.Array instance method variant of ivy.isin. This method simply wraps the function, and so the docstring for ivy.isin also applies to this method with minimal changes.

Parameters:
  • self (Array) – input array

  • test_elements (Array) – values against which to test for each input element

  • assume_unique (bool, default: False) – If True, assumes both elements and test_elements contain unique elements, which can speed up the calculation. Default value is False.

  • invert (bool, default: False) – If True, inverts the boolean return array, resulting in True values for elements not in test_elements. Default value is False.

Return type:

Array

Returns:

ret – output a boolean array of the same shape as elements that is True for elements in test_elements and False otherwise.

Examples

>>> x = ivy.array([[10, 7, 4], [3, 2, 1]])
>>> y = ivy.array([1, 2, 3])
>>> x.isin(y)
ivy.array([[False, False, False], [ True,  True,  True]])
>>> x = ivy.array([3, 2, 1, 0])
>>> y = ivy.array([1, 2, 3])
>>> x.isin(y, invert=True)
ivy.array([False, False, False,  True])
Container.isin(self, test_elements, /, *, assume_unique=False, invert=False)[source]#

Container instance method variant of ivy.isin. This method simply wraps the function, and so the docstring for ivy.isin also applies to this method with minimal changes.

Parameters:
  • self (Container) – input array

  • test_elements (Container) – values against which to test for each input element

  • assume_unique (Union[bool, Container], default: False) – If True, assumes both elements and test_elements contain unique elements, which can speed up the calculation. Default value is False.

  • invert (Union[bool, Container], default: False) – If True, inverts the boolean return array, resulting in True values for elements not in test_elements. Default value is False.

Return type:

Container

Returns:

ret – output a boolean array of the same shape as elements that is True for elements in test_elements and False otherwise.

Examples

>>> x = ivy.Container(a=[[10, 7, 4], [3, 2, 1]],                                b=[3, 2, 1, 0])
>>> y = ivy.Container(a=[1, 2, 3],                                b=[1, 0, 3])
>>> x.isin(y)
ivy.Container(a=[[False, False, False], [ True,  True,  True]],                        b=[ True, False,  True])