PyTorch torch.isinf function
PyTorch torch reference manual
torch.isinf is a function in PyTorch used to check whether values are infinite. It returns a Boolean tensor where each element is True if it is infinite (positive or negative infinity).
Function definition
torch.isinf(input)
Usage examples
Example
import
torch
Create a tensor containing different numerical values
x
=
torch.
tensor
(
[
1.0
,
float
(
'inf'
)
,
float
(
'-inf'
)
,
2.0
]
)
Check whether values are infinite
result
=
torch.
isinf
(
x
)
(
result
)
The output is:
tensor([False, True, True, False])