paddle. isfinite ( x, name=None ) [source]

Return whether every element of input tensor is finite number or not.

  • x (Tensor) – The input tensor, it’s data type should be float16, float32, float64, int32, int64.

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.


Tensor, the bool result which shows every element of x whether it is finite number or not.


import paddle

x = paddle.to_tensor([float('-inf'), -2, 3.6, float('inf'), 0, float('-nan'), float('nan')])
out = paddle.isfinite(x)
print(out)  # [False  True  True False  True False False]