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

PyTorch torch.all Function

PyTorch torch.all Function


PyTorch torch reference manual PyTorch torch reference manual

torch.all 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 True:"

,

torch.

all

(

x

)

)

Judge along dimensions

print

(

"dim=0 all True:"

,

torch.

all

(

x

,

dim

=

0

)

)

The output is:

全部为 True: tensor(False)

dim=0 全部为 True: tensor([True, False, True])


PyTorch torch reference manual PyTorch torch reference manual