torch.isin#
- torch.isin(elements, test_elements, *, assume_unique=False, invert=False) Tensor#
Tests if each element of
elementsis intest_elements. Returns a boolean tensor of the same shape aselementsthat is True for elements intest_elementsand False otherwise.Note
One of
elementsortest_elementscan be a scalar, but not both.- Parameters
elements (Tensor or Scalar) – Input elements
test_elements (Tensor or Scalar) – Values against which to test for each input element
assume_unique (bool, optional) – If True, assumes both
elementsandtest_elementscontain unique elements, which can speed up the calculation. Default: Falseinvert (bool, optional) – If True, inverts the boolean return tensor, resulting in True values for elements not in
test_elements. Default: False
- Returns
A boolean tensor of the same shape as
elementsthat is True for elements intest_elementsand False otherwise
Example
>>> torch.isin(torch.tensor([[1, 2], [3, 4]]), torch.tensor([2, 3])) tensor([[False, True], [ True, False]])