torch.nanmedian¶
- 
torch.nanmedian(input) → Tensor¶
- Returns the median of the values in - input, ignoring- NaNvalues.- This function is identical to - torch.median()when there are no- NaNvalues in- input. When- inputhas one or more- NaNvalues,- torch.median()will always return- NaN, while this function will return the median of the non-- NaNelements in- input. If all the elements in- inputare- NaNit will also return- NaN.- 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)where- valuescontains the median of each row of- inputin the dimension- dim, ignoring- NaNvalues, and- indicescontains the index of the median values found in the dimension- dim.- This function is identical to - torch.median()when there are no- NaNvalues in a reduced row. When a reduced row has one or more- NaNvalues,- torch.median()will always reduce it to- NaN, while this function will reduce it to the median of the non-- NaNelements. If all the elements in a reduced row are- NaNthen it will be reduced to- NaN, 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 - dimof- input.
 - 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]))