Rate this Page

torch.isin#

torch.isin(elements,test_elements,*,assume_unique=False,invert=False)Tensor#

Tests if each element ofelements is intest_elements. Returnsa boolean tensor of the same shape aselements that is True for elementsintest_elements and False otherwise.

Note

One ofelements ortest_elements can be a scalar, but not both.

Parameters
  • elements (Tensor orScalar) – Input elements

  • test_elements (Tensor orScalar) – Values against which to test for each input element

  • assume_unique (bool,optional) – If True, assumes bothelements andtest_elements contain unique elements, which can speed up thecalculation. Default: False

  • invert (bool,optional) – If True, inverts the boolean return tensor, resulting in Truevalues for elementsnot intest_elements. Default: False

Returns

A boolean tensor of the same shape aselements that is True for elements intest_elements and False otherwise

Example

>>>torch.isin(torch.tensor([[1,2],[3,4]]),torch.tensor([2,3]))tensor([[False,  True],        [ True, False]])