PyTorch torch.isclose function
PyTorch torch reference manual
torch.isclose is a function in PyTorch used to check whether two tensors are close. It returns a Boolean tensor indicating whether corresponding elements in the two tensors are close within a given tolerance.
Function definition
torch.isclose(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 corresponding elements are close
result
=
torch.
isclose
(
x
,
y
)
(
result
)
The output is:
tensor([True, True, True])