On this page
torch.any
torch.any(input) → Tensor-
Tests if any element in
inputevaluates toTrue.Note
This function matches the behaviour of NumPy in returning output of dtype
boolfor all supported dtypes exceptuint8. Foruint8the dtype of output isuint8itself.Example:
>>> a = torch.rand(1, 2).bool() >>> a tensor([[False, True]], dtype=torch.bool) >>> torch.any(a) tensor(True, dtype=torch.bool) >>> a = torch.arange(0, 3) >>> a tensor([0, 1, 2]) >>> torch.any(a) tensor(True)- torch.any(input, dim, keepdim=False, *, out=None) Tensor
For each row of
inputin the given dimensiondim, returnsTrueif any element in the row evaluate toTrueandFalseotherwise.If
keepdimisTrue, the output tensor is of the same size asinputexcept in the dimensiondimwhere it is of size 1. Otherwise,dimis squeezed (seetorch.squeeze()), resulting in the output tensor having 1 fewer dimension thaninput.- Parameters
- Keyword Arguments
-
out (Tensor, optional) – the output tensor.
Example:
>>> a = torch.randn(4, 2) < 0 >>> a tensor([[ True, True], [False, True], [ True, True], [False, False]]) >>> torch.any(a, 1) tensor([ True, True, True, False]) >>> torch.any(a, 0) tensor([True, True])
© 2024, PyTorch Contributors
PyTorch has a BSD-style license, as found in the LICENSE file.
https://pytorch.org/docs/2.1/generated/torch.any.html