nanmean(input: Tensor, dim: _int | Sequence[_int] | None = ..., keepdim: _bool = ..., dtype: DTypeLike | None = ...)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
inputTensorInput 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.dtypeDTypeLike | NoneTarget floating-point or complex dtype for the reduction. When
given,
input is cast to dtype before averaging.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.)