mindspore.ops.nanmedian

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

Computes the median and indices of input in specified dimension, ignoring NaN.

Warning

  • indices does not necessarily contain the first occurrence of each median value found in the input, unless it is unique.

  • Non-backward-compatible change after version 2.9.0: axis will be renamed to dim and its default value will change. The return value will differ based on whether dim is specified: when unspecified, only the median is returned; when specified, a tuple (median, indices) is returned.

Parameters
  • input (Tensor) – The input tensor.

  • axis (int, optional) – The specified axis for computation. Default -1 .

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

Returns

Tuple(median, median_indices)

Supported Platforms:

CPU

Examples

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