PyTorch torch.any Function


Pytorch torch 参考手册Pytorch torch Reference Manual

torch.anyIt is a function in PyTorch used to determine whether any element is True.

Function Definition

torch.any(input, dim, keepdim, out)

Usage Example

Example

import torch

x = torch.tensor([[True, False, False], [False, False, False]])

print("Has True:", torch.any(x))
print("dim=0 Has True:", torch.any(x, dim=0))

The output result is:

有 True: tensor(True)
dim=0 有 True: tensor([True, False, False])

Pytorch torch 参考手册Pytorch torch Reference Manual

Other Extensions