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

PyTorch torch.allclose function

PyTorch torch.allclose function


PyTorch torch reference manual PyTorch torch reference manual

torch.allclose is a function in PyTorch used to check whether all elements of two tensors are close. It determines whether two tensors are equal within a given tolerance.

Function definition

torch.allclose(input, other, rtol=1e-05, atol=1e-08, equal_nan=False)


Usage examples

Example

import

torch

Create two close tensors

x

=

torch.

tensor

(

[

1.0

,

2.0

,

3.0

]

)

y

=

torch.

tensor

(

[

1.0

,

2.0

,

3.0

1e-9

]

)

Check whether all elements are close

result

=

torch.

allclose

(

x

,

y

)

print

(

result

)

The output is:

True


PyTorch torch reference manual PyTorch torch reference manual