torch.nanmedian#
- torch.nanmedian(input)→Tensor#
Returns the median of the values in
input, ignoringNaNvalues.This function is identical to
torch.median()when there are noNaNvalues ininput.Wheninputhas one or moreNaNvalues,torch.median()will always returnNaN,while this function will return the median of the non-NaNelements ininput.If all the elements ininputareNaNit 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)wherevaluescontains the median of each row ofinputin the dimensiondim, ignoringNaNvalues, andindicescontains the index of the median valuesfound in the dimensiondim.This function is identical to
torch.median()when there are noNaNvalues in a reduced row. When a reduced row hasone or moreNaNvalues,torch.median()will always reduce it toNaN, while this function will reduce it to themedian of the non-NaNelements. If all the elements in a reduced row areNaNthen 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 secondtensor, which must have dtype long, with their indices in the dimension
dimofinput.
Example:
>>>a=torch.tensor([[2,3,1],[float('nan'),1,float('nan')]])>>>atensor([[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]))