Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.isinf function

PyTorch torch.isinf function


PyTorch torch reference manual 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

)

print

(

result

)

The output is:

tensor([False, True, True, False])


PyTorch torch reference manual PyTorch torch reference manual