nanmedian¶
- paddle. nanmedian ( x, axis=None, keepdim=False, name=None ) [source]
-
Compute the median along the specified axis, while ignoring NaNs.
If the valid count of elements is a even number, the average value of both elements in the middle is calculated as the median.
- Parameters
-
x (Tensor) – The input Tensor, it’s data type can be int32, int64, float16, bfloat16, float32, float64.
axis (None|int|list|tuple, optional) – The axis along which to perform median calculations
axis
should be int or list of int.axis
should be in range [-D, D), where D is the dimensions ofx
. Ifaxis
is less than 0, it works the same way as \(axis + D\). Ifaxis
is 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
keepdim
is True, the dimensions of the output Tensor is the same asx
except 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
axis
ofx
. The output dtype is the same as x.
Examples
>>> import paddle >>> x = paddle.to_tensor([[float('nan'), 2. , 3. ], [0. , 1. , 2. ]]) >>> y1 = x.nanmedian() >>> print(y1.numpy()) 2.0 >>> y2 = x.nanmedian(0) >>> print(y2.numpy()) [0. 1.5 2.5] >>> y3 = x.nanmedian(0, keepdim=True) >>> print(y3.numpy()) [[0. 1.5 2.5]] >>> y4 = x.nanmedian((0, 1)) >>> print(y4.numpy()) 2.0