PyTorch torch.isfinite Function
PyTorch torch Reference Manual
torch.isfiniteThis is a function in PyTorch used to check whether tensor elements are finite values. It returns a Boolean tensor, where for each element, it is True if the value is finite (not infinity or NaN).
Function Definition
torch.isfinite(input)
Usage Example
Example
import torch
# Create a tensor containing different values
x = torch.tensor([1.0, float('inf'), float('nan'), 2.0])
# Check for finite values
result = torch.isfinite(x)
print(result)
# Create a tensor containing different values
x = torch.tensor([1.0, float('inf'), float('nan'), 2.0])
# Check for finite values
result = torch.isfinite(x)
print(result)
The output is:
tensor([True, False, False, True])
Other Extensions