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.| Parameter | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input array. |
axis | number | number[] | undefined | Axis or axes along which to sum. |
keepdims | boolean | false | If true, reduced axes are kept as dimensions with size 1. |
number when reducing all axes, NDArray when reducing along specific axes.
nanprod
Return the product of array elements, treating NaN as one.| Parameter | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input array. |
axis | number | number[] | undefined | Axis or axes along which to compute the product. |
keepdims | boolean | false | If true, reduced axes are kept as dimensions with size 1. |
number when reducing all axes, NDArray when reducing along specific axes.
nanmean
Compute the arithmetic mean, ignoring NaN values.| Parameter | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input array. |
axis | number | number[] | undefined | Axis or axes along which to compute the mean. |
keepdims | boolean | false | If true, reduced axes are kept as dimensions with size 1. |
number when reducing all axes, NDArray when reducing along specific axes.
nanstd
Compute the standard deviation, ignoring NaN values.| Parameter | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input array. |
axis | number | number[] | undefined | Axis or axes along which to compute the standard deviation. |
ddof | number | 0 | Delta degrees of freedom. |
keepdims | boolean | false | If true, reduced axes are kept as dimensions with size 1. |
number when reducing all axes, NDArray when reducing along specific axes.
nanvar
Compute the variance, ignoring NaN values.| Parameter | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input array. |
axis | number | number[] | undefined | Axis or axes along which to compute the variance. |
ddof | number | 0 | Delta degrees of freedom. |
keepdims | boolean | false | If true, reduced axes are kept as dimensions with size 1. |
number when reducing all axes, NDArray when reducing along specific axes.
nanmin
Return the minimum, ignoring NaN values.| Parameter | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input array. |
axis | number | number[] | undefined | Axis or axes along which to find the minimum. |
keepdims | boolean | false | If true, reduced axes are kept as dimensions with size 1. |
number when reducing all axes, NDArray when reducing along specific axes.
nanmax
Return the maximum, ignoring NaN values.| Parameter | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input array. |
axis | number | number[] | undefined | Axis or axes along which to find the maximum. |
keepdims | boolean | false | If true, reduced axes are kept as dimensions with size 1. |
number when reducing all axes, NDArray when reducing along specific axes.
nanmedian
Compute the median, ignoring NaN values.| Parameter | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input array. |
axis | number | number[] | undefined | Axis or axes along which to compute the median. |
keepdims | boolean | false | If true, reduced axes are kept as dimensions with size 1. |
number when reducing all axes, NDArray when reducing along specific axes.
nancumsum
Return the cumulative sum, treating NaN as zero.| Parameter | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input array. |
axis | number | undefined | Axis along which to compute. When undefined, the input is flattened. |
NDArray containing the cumulative sums with NaN replaced by zero.
nancumprod
Return the cumulative product, treating NaN as one.| Parameter | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input array. |
axis | number | undefined | Axis along which to compute. When undefined, the input is flattened. |
NDArray containing the cumulative products with NaN replaced by one.
nanargmin
Return the index of the minimum value, ignoring NaN.| Parameter | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input array. |
axis | number | undefined | Axis along which to search. When undefined, operates on the flattened array. |
number when no axis is specified, NDArray of indices when an axis is given.
nanargmax
Return the index of the maximum value, ignoring NaN.| Parameter | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input array. |
axis | number | undefined | Axis along which to search. When undefined, operates on the flattened array. |
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.| Parameter | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input array. |
q | number | number[] | — | Percentile(s) to compute, in the range [0, 100]. |
axis | number | number[] | undefined | Axis or axes along which to compute. |
keepdims | boolean | false | If true, reduced axes are kept as dimensions with size 1. |
number for a single percentile over all axes, NDArray otherwise.
nanquantile
Compute the q-th quantile of the data, ignoring NaN values.| Parameter | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input array. |
q | number | number[] | — | Quantile(s) to compute, in the range [0, 1]. |
axis | number | number[] | undefined | Axis or axes along which to compute. |
keepdims | boolean | false | If true, reduced axes are kept as dimensions with size 1. |
number for a single quantile over all axes, NDArray otherwise.