
Last chance! 50% off unlimited learning
Sale ends in
Quantile
torch_quantile(self, q, dim = NULL, keepdim = FALSE)
(Tensor) the input tensor.
(float or Tensor) a scalar or 1D tensor of quantile values in the range [0, 1]
(int) the dimension to reduce.
(bool) whether the output tensor has dim
retained or not.
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.
Returns the q-th quantiles of each row of the input
tensor along the dimension
dim
, doing a linear interpolation when the q-th quantile lies between two
data points. By default, dim
is None
resulting in the input
tensor
being flattened before computation.
If keepdim
is TRUE
, the output dimensions are of the same size as input
except in the dimensions being reduced (dim
or all if dim
is NULL
) where they
have size 1. Otherwise, the dimensions being reduced are squeezed (see torch_squeeze
).
If q
is a 1D tensor, an extra dimension is prepended to the output tensor with the same
size as q
which represents the quantiles.
# NOT RUN {
if (torch_is_installed()) {
a <- torch_randn(c(1, 3))
a
q <- torch_tensor(c(0, 0.5, 1))
torch_quantile(a, q)
a <- torch_randn(c(2, 3))
a
q <- torch_tensor(c(0.25, 0.5, 0.75))
torch_quantile(a, q, dim=1, keepdim=TRUE)
torch_quantile(a, q, dim=1, keepdim=TRUE)$shape
}
# }
Run the code above in your browser using DataLab