torch.nanquantile#
- torch.nanquantile(input, q, dim=None, keepdim=False, *, interpolation='linear', out=None) Tensor #
This is a variant of
torch.quantile()
that โignoresโNaN
values, computing the quantilesq
as ifNaN
values ininput
did not exist. If all values in a reduced row areNaN
then the quantiles for that reduction will beNaN
. See the documentation fortorch.quantile()
.- Parameters
input (Tensor) โ the input tensor.
q (float or Tensor) โ a scalar or 1D tensor of quantile values in the range [0, 1]
dim (int, optional) โ the dimension to reduce. If
None
, all dimensions are reduced.keepdim (bool, optional) โ whether the output tensor has
dim
retained or not. Default:False
.
- Keyword Arguments
Example:
>>> t = torch.tensor([float('nan'), 1, 2]) >>> t.quantile(0.5) tensor(nan) >>> t.nanquantile(0.5) tensor(1.5000) >>> t = torch.tensor([[float('nan'), float('nan')], [1, 2]]) >>> t tensor([[nan, nan], [1., 2.]]) >>> t.nanquantile(0.5, dim=0) tensor([1., 2.]) >>> t.nanquantile(0.5, dim=1) tensor([ nan, 1.5000])