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

PyTorch torch.isfinite function

PyTorch torch.isfinite function


PyTorch torch reference manual PyTorch torch reference manual

torch.isfinite is a function in PyTorch used to check whether tensor elements have finite values. It returns a Boolean tensor where each element is True if it is a finite value (not infinity or NaN).

Function definition

torch.isfinite(input)


Usage examples

Example

import

torch

Create a tensor containing different numerical values

x

=

torch.

tensor

(

[

1.0

,

float

(

'inf'

)

,

float

(

'nan'

)

,

2.0

]

)

Check whether values are finite

result

=

torch.

isfinite

(

x

)

print

(

result

)

The output is:

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


PyTorch torch reference manual PyTorch torch reference manual