# median¶

`paddle.` `median` ( x, axis=None, keepdim=False, name=None ) [source]

Compute the median along the specified axis.

Parameters
• x (Tensor) – The input Tensor, it’s data type can be bool, float16, float32, float64, int32, int64.

• axis (int, optional) – The axis along which to perform median calculations `axis` should be int. `axis` should be in range [-D, D), where D is the dimensions of `x` . If `axis` is less than 0, it works the same way as \(axis + D\). If `axis` is None, median is calculated over all elements of `x`. Default is None.

• keepdim (bool, optional) – Whether to reserve the reduced dimension(s) in the output Tensor. If `keepdim` is True, the dimensions of the output Tensor is the same as `x` except in the reduced dimensions(it is of size 1 in this case). Otherwise, the shape of the output Tensor is squeezed in `axis` . Default is False.

• name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

Tensor, results of median along `axis` of `x`. If data type of `x` is float64, data type of results will be float64, otherwise data type will be float32.

Examples

```import paddle

x = paddle.arange(12).reshape([3, 4])
# x is [[0 , 1 , 2 , 3 ],
#       [4 , 5 , 6 , 7 ],
#       [8 , 9 , 10, 11]]

y1 = paddle.median(x)
# y1 is [5.5]

y2 = paddle.median(x, axis=0)
# y2 is [4., 5., 6., 7.]

y3 = paddle.median(x, axis=1)
# y3 is [1.5, 5.5, 9.5]

y4 = paddle.median(x, axis=0, keepdim=True)
# y4 is [[4., 5., 6., 7.]]
```