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 of- x. If- 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. 
 
- 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]) # Tensor(shape=[3, 4], dtype=int64, place=Place(cpu), stop_gradient=True, # [[0 , 1 , 2 , 3 ], # [4 , 5 , 6 , 7 ], # [8 , 9 , 10, 11]]) y1 = paddle.median(x) # Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True, # [5.50000000]) y2 = paddle.median(x, axis=0) # Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True, # [4., 5., 6., 7.]) y3 = paddle.median(x, axis=1) # Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True, # [1.50000000, 5.50000000, 9.50000000]) y4 = paddle.median(x, axis=0, keepdim=True) # Tensor(shape=[1, 4], dtype=float32, place=Place(cpu), stop_gradient=True, # [[4., 5., 6., 7.]]) 
