latest (dev)
Copy
Latest development documentation · Updated 2026-10-15
tensorplay.functional.nanmean
- tensorplay.functional.nanmean(input, dim=None, keepdim=False, *, dtype=None, out=None) Tensor[source]
Computes the mean of all non-NaN elements along the specified dimensions. Input must be floating point or complex.
This function is identical to
tensorplay.mean()when there are no NaN values in theinputtensor. In the presence of NaN,tensorplay.mean()will propagate the NaN to the output whereastensorplay.nanmean()will ignore the NaN values (tensorplay.nanmean(a) is equivalent to tensorplay.mean(a[~a.isnan()])).If
keepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).- Parameters:
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. If specified, the input tensor is casted todtypebefore the operation is performed. This is useful for preventing data type overflows. Default: None.out (Tensor, optional) – the output tensor.
See also
tensorplay.mean()computes the mean value, propagating NaN.Example:
>>> x = tensorplay.tensor([[tensorplay.nan, 1, 2], [1, 2, 3]]) >>> x.mean() tensor(nan) >>> x.nanmean() tensor(1.8000) >>> x.mean(dim=0) tensor([ nan, 1.5000, 2.5000]) >>> x.nanmean(dim=0) tensor([1.0000, 1.5000, 2.5000]) # If all elements in the reduced dimensions are NaN then the result is NaN >>> tensorplay.tensor([tensorplay.nan]).nanmean() tensor(nan)
Help improve this page
Found an error, an unclear step, or a missing example?

