torch.all
-
torch.all(input: Tensor, *, out=None) → Tensor -
Tests if all elements in
inputevaluate toTrue.Note
This function matches the behaviour of NumPy in returning output of dtype
boolfor all supported dtypes exceptuint8. Foruint8the dtype of output isuint8itself.- Parameters
-
input (Tensor) – the input tensor.
- Keyword Arguments
-
out (Tensor, optional) – the output tensor.
Example:
>>> a = torch.rand(1, 2).bool() >>> a tensor([[False, True]], dtype=torch.bool) >>> torch.all(a) tensor(False, dtype=torch.bool) >>> a = torch.arange(0, 3) >>> a tensor([0, 1, 2]) >>> torch.all(a) tensor(False)
- torch.all(input, dim, keepdim=False, *, out=None) Tensor
For each row of
inputin the given dimensiondim, returnsTrueif all elements in the row evaluate toTrueandFalseotherwise.If
keepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetorch.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).- Parameters
- Keyword Arguments
-
out (Tensor, optional) – the output tensor.
Example:
>>> a = torch.rand(4, 2).bool() >>> a tensor([[True, True], [True, False], [True, True], [True, True]], dtype=torch.bool) >>> torch.all(a, dim=1) tensor([ True, False, True, True], dtype=torch.bool) >>> torch.all(a, dim=0) tensor([ True, False], dtype=torch.bool)