mindspore.ops.nanmedian

View Source On Gitee
mindspore.ops.nanmedian(input, axis=- 1, keepdims=False)[source]

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

Warning

indices does not necessarily contain the first occurrence of each median value found in the input,

unless it is unique.

Parameters
  • input (Tensor) – The input tensor to calculate the median and indices.

  • axis (int, optional) – The dimension need to calculate median and indices. Default: -1 , calculate the last dimension.

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

Returns

Tensor, the median of input along the specified dimension, has the same dtype as input.

indices (Tensor), median index, dtype is int64.

Raises
  • TypeError – If dtype of input is not one of the following: int16, int32, int64, float32, float64.

  • TypeError – If input input is not a Tensor.

  • TypeError – If axis is not int.

  • TypeError – If keepdims is not bool.

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

Supported Platforms:

CPU

Examples

>>> import mindspore
>>> from mindspore import Tensor, ops
>>> x = Tensor([[0.57, 0.11, float("nan")],
...             [0.38, float("nan"), float("nan")],
...             [0.36, 0.16, float("nan")]], mindspore.float32)
>>> y, idx = ops.nanmedian(x, axis=0, keepdims=False)
>>> print(y)
[0.38 0.11  nan]
>>> print(idx)
[1 0 0]