torch.quantile¶
-
torch.
quantile
(input, q) → Tensor¶ Returns the q-th quantiles of all elements in the
input
tensor, doing a linear interpolation when the q-th quantile lies between two data points.- Parameters
Example:
>>> a = torch.randn(1, 3) >>> a tensor([[ 0.0700, -0.5446, 0.9214]]) >>> q = torch.tensor([0, 0.5, 1]) >>> torch.quantile(a, q) tensor([-0.5446, 0.0700, 0.9214])
-
torch.
quantile
(input, q, dim=None, keepdim=False, *, out=None) → Tensor¶
Returns the q-th quantiles of each row of the
input
tensor along the dimensiondim
, doing a linear interpolation when the q-th quantile lies between two data points. By default,dim
isNone
resulting in theinput
tensor being flattened before computation.If
keepdim
isTrue
, the output dimensions are of the same size asinput
except in the dimensions being reduced (dim
or all ifdim
isNone
) where they have size 1. Otherwise, the dimensions being reduced are squeezed (seetorch.squeeze()
). Ifq
is a 1D tensor, an extra dimension is prepended to the output tensor with the same size asq
which represents the quantiles.- Parameters
- Keyword Arguments
out (Tensor, optional) – the output tensor.
Example:
>>> a = torch.randn(2, 3) >>> a tensor([[ 0.0795, -1.2117, 0.9765], [ 1.1707, 0.6706, 0.4884]]) >>> q = torch.tensor([0.25, 0.5, 0.75]) >>> torch.quantile(a, q, dim=1, keepdim=True) tensor([[[-0.5661], [ 0.5795]], [[ 0.0795], [ 0.6706]], [[ 0.5280], [ 0.9206]]]) >>> torch.quantile(a, q, dim=1, keepdim=True).shape torch.Size([3, 2, 1])