mindspore.numpy.nansum

mindspore.numpy.nansum(a, axis=None, dtype=None, keepdims=False)[源代码]

Returns the sum of array elements over a given axis treating Not a Numbers (NaNs) as zero.

Note

Numpy arguments out is not supported.

Parameters
  • a (Union[int, float, list, tuple, Tensor]) – Array containing numbers whose sum is desired. If a is not an array, a conversion is attempted.

  • axis (Union[int, tuple of int, None], optional) – Axis or axes along which the sum is computed. The default is to compute the sum of the flattened array.

  • dtype (mindspore.dtype, optional) – Defaults to None. Overrides the dtype of the output Tensor.

  • keepdims (boolean, optional) – Defaults to False. If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original a.

Returns

Tensor.

Raises

ValueError – If axes are out of the range of [-a.ndim, a.ndim), or if the axes contain duplicates.

Supported Platforms:

GPU CPU

Examples

>>> import mindspore.numpy as np
>>> a = np.array([[1, 1], [1, np.nan]])
>>> output = np.nansum(a)
>>> print(output)
3.0
>>> output = np.nansum(a, axis=0)
>>> print(output)
[2. 1.]