mindspore.mint.median
- mindspore.mint.median(input, dim=None, keepdim=False)[source]
Output the median on the specified dimension
dim
and its corresponding index. Ifdim
is None, calculate the median of all elements in the Tensor.- Parameters
- Returns
y (Tensor) - Output median, with the same data type as
input
.If
dim
isNone
,y
only has one element.If
keepdim
isTrue
, they
has the same shape as theinput
except the shape ofy
in dimension dim is size 1.Otherwise, the
y
lacks dim dimension than input.
indices (Tensor) - The index of the median. Shape is consistent with
y
, with a data type of int64.
- Raises
TypeError – If dtype of
input
is not one of the following: uint8, int16, int32, int64, float16 or float32.TypeError – If input
input
is not a Tensor.TypeError – If
dim
is not a int.TypeError – If
keepdim
is not a bool.ValueError – If
dim
is not in range of [-x.dim, x.dim-1].
- Supported Platforms:
Ascend
Examples
>>> import numpy as np >>> from mindspore import Tensor, mint >>> x = Tensor(np.array([[0.57, 0.11, 0.21],[0.38, 0.50, 0.57], [0.36, 0.16, 0.44]]).astype(np.float32)) >>> y = mint.median(x, dim=0, keepdim=False) >>> print(y) (Tensor(shape=[3], dtype=Float32, value= [ 3.79999995e-01, 1.59999996e-01, 4.39999998e-01]), Tensor(shape=[3], dtype=Int64, value= [1, 2, 2]))