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
axisshould be int.axisshould be in range [-D, D), where D is the dimensions ofx. Ifaxisis less than 0, it works the same way as \(axis + D\). Ifaxisis None, median is calculated over all elements ofx. 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 asxexcept in the reduced dimensions(it is of size 1 in this case). Otherwise, the shape of the output Tensor is squeezed inaxis. 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
axisofx. If data type ofxis 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.]]
