mindspore.ops.nanmean

View Source On Gitee
mindspore.ops.nanmean(input, axis=None, keepdims=False, *, dtype=None)[source]

Computes the mean of input in specified dimension, ignoring NaN. If all elements in the specified dimensions are NaN, the result will be NaN.

Parameters
  • input (Tensor) – The input tensor to calculate the mean.

  • axis (int, optional) – The dimension need to reduce. Default: None, all dimensions are reduced.

  • keepdims (bool, optional) – Whether the output tensor needs to retain dimension or not. Default: False, not to retain dimensions.

Keyword Arguments

dtype (mindspore.dtype, optional) – The output Tensor data type. Default: None , the data type of output Tensor is same as the input.

Returns

Tensor, the mean of input input in the given dimension axis, while ignoring NaNs.

Raises
  • TypeError – If input is not a Tensor.

  • TypeError – If axis is not int.

  • TypeError – If keepdims is not bool.

  • TypeError – If dtype is not mindspore dtype.

  • ValueError – If axis is not in range of [-r, r) which r means the rank of input.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> from mindspore import Tensor, ops
>>> x = Tensor([[0.5, -1.1, float('nan')], [3.4, float('nan'), float('nan')]], mindspore.float32)
>>> y = ops.nanmean(x, axis=0, keepdims=False)
>>> print(y)
[ 1.95 -1.1    nan]