mindspore.ops.NanToNum

View Source On Gitee
class mindspore.ops.NanToNum(nan=0.0, posinf=None, neginf=None)[source]

Replaces NaN, positive infinity and negative infinity values in the input Tensor with the values specified by nan, posinf and neginf respectively.

Warning

This is an experimental API that is subject to change or deletion.

Refer to mindspore.ops.nan_to_num() for more details.

Parameters
  • nan (float, optional) – The value to replace NaN. Default value is 0.0 .

  • posinf (float, optional) – If a Number, the value to replace positive infinity values with. If None, positive infinity values are replaced with the greatest finite value representable by x’s dtype. Default value is None .

  • neginf (float, optional) – if a Number, the value to replace negative infinity values with. If None, negative infinity values are replaced with the lowest finite value representable by x’s dtype. Default value is None .

Inputs:
  • x (Tensor) - Input Tensor of any dimensions. Supported data types: float32 or float16.

Outputs:

Tensor, has the same shape and dtype as the x.

Supported Platforms:

Ascend CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> nan_to_num = ops.NanToNum()
>>> x = Tensor(np.array([float('nan'), float('inf'), -float('inf'), 3.14]), mindspore.float32)
>>> output = nan_to_num(x)
>>> print(output)
[ 0.0000000e+00  3.4028235e+38 -3.4028235e+38  3.1400001e+00]