median( x, axis=None, keepdim=False, name=None )
Compute the median along the specified axis.
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
axisshould be int.
axisshould be in range [-D, D), where D is the dimensions of
axisis less than 0, it works the same way as \(axis + D\). If
axisis 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
keepdimis True, the dimensions of the output Tensor is the same as
xexcept 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.
Tensor, results of median along
x. If data type of
xis float64, data type of results will be float64, otherwise data type will be float32.
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.]]