Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.any function

PyTorch torch.any function


PyTorch torch reference manual 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

]

]

)

print

(

"Has True:"

,

torch.

any

(

x

)

)

print

(

"dim=0 has True:"

,

torch.

any

(

x

,

dim

=

0

)

)

The output is:

有 True: tensor(True)

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


PyTorch torch reference manual PyTorch torch reference manual