torch.nanmedian¶
-
torch.
nanmedian
(input) → Tensor¶ Returns the median of the values in
input
, ignoringNaN
values.This function is identical to
torch.median()
when there are noNaN
values ininput
. Wheninput
has one or moreNaN
values,torch.median()
will always returnNaN
, while this function will return the median of the non-NaN
elements ininput
. If all the elements ininput
areNaN
it will also returnNaN
.- Parameters
input (Tensor) – the input tensor.
Example:
>>> a = torch.tensor([1, float('nan'), 3, 2]) >>> a.median() tensor(nan) >>> a.nanmedian() tensor(2.)
-
torch.
nanmedian
(input, dim=- 1, keepdim=False, *, out=None)¶
Returns a namedtuple
(values, indices)
wherevalues
contains the median of each row ofinput
in the dimensiondim
, ignoringNaN
values, andindices
contains the index of the median values found in the dimensiondim
.This function is identical to
torch.median()
when there are noNaN
values in a reduced row. When a reduced row has one or moreNaN
values,torch.median()
will always reduce it toNaN
, while this function will reduce it to the median of the non-NaN
elements. If all the elements in a reduced row areNaN
then it will be reduced toNaN
, too.- Parameters
- Keyword Arguments
out ((Tensor, Tensor), optional) – The first tensor will be populated with the median values and the second tensor, which must have dtype long, with their indices in the dimension
dim
ofinput
.
Example:
>>> a = torch.tensor([[2, 3, 1], [float('nan'), 1, float('nan')]]) >>> a tensor([[2., 3., 1.], [nan, 1., nan]]) >>> a.median(0) torch.return_types.median(values=tensor([nan, 1., nan]), indices=tensor([1, 1, 1])) >>> a.nanmedian(0) torch.return_types.nanmedian(values=tensor([2., 1., 1.]), indices=tensor([0, 1, 0]))