quantile¶
- paddle. quantile ( x, q, axis=None, keepdim=False ) [source]
-
Compute the quantile of the input along the specified axis. If any 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.
axisshould be int or list of 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 a list, quantile is calculated over all elements of given axises. Ifaxisis None, quantile 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 quantile along
axisofx. In order to obtain higher precision, data type of results will be float64.
Examples
import paddle y = paddle.arange(0, 8 ,dtype="float32").reshape([4, 2]) # Tensor(shape=[4, 2], dtype=float32, place=Place(cpu), stop_gradient=True, # [[0., 1.], # [2., 3.], # [4., 5.], # [6., 7.]]) y1 = paddle.quantile(y, q=0.5, axis=[0, 1]) # Tensor(shape=[], dtype=float64, place=Place(cpu), stop_gradient=True, # 3.50000000) y2 = paddle.quantile(y, q=0.5, axis=1) # Tensor(shape=[4], dtype=float64, place=Place(cpu), stop_gradient=True, # [0.50000000, 2.50000000, 4.50000000, 6.50000000]) y3 = paddle.quantile(y, q=[0.3, 0.5], axis=0) # Tensor(shape=[2, 2], dtype=float64, place=Place(cpu), stop_gradient=True, # [[1.80000000, 2.80000000], # [3. , 4. ]]) y[0,0] = float("nan") y4 = paddle.quantile(y, q=0.8, axis=1, keepdim=True) # Tensor(shape=[4, 1], dtype=float64, place=Place(cpu), stop_gradient=True, # [[nan ], # [2.80000000], # [4.80000000], # [6.80000000]])
