fn
nanmean
→Tensornanmean(x: Tensor, dim: int | Sequence[int] | None = ..., keepdim: bool = ...)Mean of the tensor, ignoring NaN entries.
A NaN-safe variant of lucid.mean. Both the numerator (sum)
and the denominator (element count) are computed only over the
non-NaN entries.
Parameters
xTensorInput tensor (any floating-point dtype).
dimint | Sequence[int] | NoneAxis or axes along which to take the mean.
None (default)
reduces over the entire tensor.keepdimboolIf
True, retains the reduced dimensions with size 1.
Defaults to False.Returns
TensorReduced tensor.
Notes
With the set of indices being reduced and ,
A slice that is entirely NaN produces 0 / 0 = NaN; this is the
standard convention. The gradient at NaN positions is zero.
Examples
>>> import lucid
>>> import math
>>> x = lucid.tensor([1.0, math.nan, 3.0])
>>> lucid.nanmean(x)
Tensor(2.)