PyTorch torch.any function
PyTorch torch reference manual
torch.any is a function in PyTorch used to check whether any element is True.
Function definition
torch.any(input, dim, keepdim, out)
Usage examples
Example
import
torch
x
=
torch.
tensor
(
[
[
True
,
False
,
False
]
,
[
False
,
False
,
False
]
]
)
(
"Has True:"
,
torch.
any
(
x
)
)
(
"dim=0 has True:"
,
torch.
any
(
x
,
dim
=
0
)
)
The output is:
有 True: tensor(True)
dim=0 有 True: tensor([True, False, False])