PyTorch torch.isclose Function
Pytorch torch Reference Manual
torch.iscloseIt is a function in PyTorch used to check whether two tensors are close. Returns a boolean tensor indicating whether the 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 Example
Example
import torch
# Create two similar tensors
x = torch.tensor([1.0, 2.0, 3.0])
y = torch.tensor([1.0, 2.0, 3.0 + 1e-9])
# Check whether the corresponding elements are close
result = torch.isclose(x, y)
print(result)
# Create two similar tensors
x = torch.tensor([1.0, 2.0, 3.0])
y = torch.tensor([1.0, 2.0, 3.0 + 1e-9])
# Check whether the corresponding elements are close
result = torch.isclose(x, y)
print(result)
The output result is:
tensor([True, True, True])
Other Extensions