nanquantile

paddle. nanquantile ( x, q, axis=None, keepdim=False ) [source]

Compute the quantile of the input as if NaN values in input did not exist. If all values in a reduced row are NaN, then the quantiles for that reduction will be NaN.

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

  • q (int|float|list) – The q for calculate quantile, which should be in range [0, 1]. If q is a list, each q will be calculated and the first dimension of output is same to the number of q .

  • axis (int|list, optional) – The axis along which to calculate quantile. axis should be int or list of 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 a list, quantile is calculated over all elements of given axises. If axis is None, quantile 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 quantile along axis of x. In order to obtain higher precision, data type of results will be float64.

Examples

>>> import paddle

>>> x = paddle.to_tensor(
...     [[0, 1, 2, 3, 4],
...      [5, 6, 7, 8, 9]],
...     dtype="float32")
>>> x[0,0] = float("nan")

>>> y1 = paddle.nanquantile(x, q=0.5, axis=[0, 1])
>>> print(y1)
Tensor(shape=[], dtype=float64, place=Place(cpu), stop_gradient=True,
5.)

>>> y2 = paddle.nanquantile(x, q=0.5, axis=1)
>>> print(y2)
Tensor(shape=[2], dtype=float64, place=Place(cpu), stop_gradient=True,
[2.50000000, 7.        ])

>>> y3 = paddle.nanquantile(x, q=[0.3, 0.5], axis=0)
>>> print(y3)
Tensor(shape=[2, 5], dtype=float64, place=Place(cpu), stop_gradient=True,
[[5.        , 2.50000000, 3.50000000, 4.50000000, 5.50000000],
 [5.        , 3.50000000, 4.50000000, 5.50000000, 6.50000000]])

>>> y4 = paddle.nanquantile(x, q=0.8, axis=1, keepdim=True)
>>> print(y4)
Tensor(shape=[2, 1], dtype=float64, place=Place(cpu), stop_gradient=True,
[[3.40000000],
 [8.20000000]])

>>> nan = paddle.full(shape=[2, 3], fill_value=float("nan"))
>>> y5 = paddle.nanquantile(nan, q=0.8, axis=1, keepdim=True)
>>> print(y5)
Tensor(shape=[2, 1], dtype=float64, place=Place(cpu), stop_gradient=True,
[[nan],
 [nan]])