PyTorch torch.all Function
Pytorch torch Reference Manual
torch.allIt is a function in PyTorch used to determine whether all elements are True.
Function Definition
torch.all(input, dim, keepdim, out)
Usage Examples
Example
import torch
x = torch.tensor([[True, True, True], [True, False, True]])
# Global check
print("All are True:", torch.all(x))
# Check along dimension
print("dim=0 all are True:", torch.all(x, dim=0))
x = torch.tensor([[True, True, True], [True, False, True]])
# Global check
print("All are True:", torch.all(x))
# Check along dimension
print("dim=0 all are True:", torch.all(x, dim=0))
The output is:
全部为 True: tensor(False) dim=0 全部为 True: tensor([True, False, True])
Other Extensions