PyTorch torch.isinf Function
Pytorch torch Reference Manual
torch.isinfis a function in PyTorch used to check whether a value is infinite. Returns a boolean tensor where, for each element, it is True if the value is infinite (positive infinity or negative infinity).
Function Definition
torch.isinf(input)
Usage Example
Example
import torch
# Create a tensor containing different values
x = torch.tensor([1.0, float('inf'), float('-inf'), 2.0])
# Check whether the values are infinite
result = torch.isinf(x)
print(result)
# Create a tensor containing different values
x = torch.tensor([1.0, float('inf'), float('-inf'), 2.0])
# Check whether the values are infinite
result = torch.isinf(x)
print(result)
The output result is:
tensor([False, True, True, False])
Other Extensions