PyTorch torch.isnan function


Pytorch torch 参考手册Pytorch torch Reference Manual

torch.isnanis a function in PyTorch used to check whether a value is NaN.

Function Definition

torch.isnan(input)

Usage Example

Example

import torch
import math

x = torch.tensor([1.0, math.nan, 3.0, float('nan')])

result = torch.isnan(x)

print(result)

The output result is:

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

Pytorch torch 参考手册Pytorch torch Reference Manual

Other Extensions