Skip to main content

NaN-Safe Reductions

These functions are identical to their non-nan counterparts but ignore NaN values instead of propagating them through the computation. Use them when your data may contain missing or invalid values represented as NaN.

nansum

Return the sum of array elements, treating NaN as zero.
Returns: number when reducing all axes, NDArray when reducing along specific axes.

nanprod

Return the product of array elements, treating NaN as one.
Returns: number when reducing all axes, NDArray when reducing along specific axes.

nanmean

Compute the arithmetic mean, ignoring NaN values.
Returns: number when reducing all axes, NDArray when reducing along specific axes.

nanstd

Compute the standard deviation, ignoring NaN values.
Returns: number when reducing all axes, NDArray when reducing along specific axes.

nanvar

Compute the variance, ignoring NaN values.
Returns: number when reducing all axes, NDArray when reducing along specific axes.

nanmin

Return the minimum, ignoring NaN values.
Returns: number when reducing all axes, NDArray when reducing along specific axes.

nanmax

Return the maximum, ignoring NaN values.
Returns: number when reducing all axes, NDArray when reducing along specific axes.

nanmedian

Compute the median, ignoring NaN values.
Returns: number when reducing all axes, NDArray when reducing along specific axes.

nancumsum

Return the cumulative sum, treating NaN as zero.
Returns: NDArray containing the cumulative sums with NaN replaced by zero.

nancumprod

Return the cumulative product, treating NaN as one.
Returns: NDArray containing the cumulative products with NaN replaced by one.

nanargmin

Return the index of the minimum value, ignoring NaN.
Returns: number when no axis is specified, NDArray of indices when an axis is given.

nanargmax

Return the index of the maximum value, ignoring NaN.
Returns: number when no axis is specified, NDArray of indices when an axis is given.

nanpercentile

Compute the q-th percentile of the data, ignoring NaN values.
Returns: number for a single percentile over all axes, NDArray otherwise.

nanquantile

Compute the q-th quantile of the data, ignoring NaN values.
Returns: number for a single quantile over all axes, NDArray otherwise.