import numpy as np
from dascore.utils.array_api import nan_reduce
array = np.array([1.0, np.nan, 3.0])
assert nan_reduce("mean", array) == 2.0nan_reduce
nan_reduce(
name: str ,
array: Any ,
axis = None,
keepdims: bool = False,
)-> ‘Any’
Reduce an array along an axis, ignoring nans.
The backend’s own implementation is used when it has one, since it is both faster and exactly what dascore did before it supported other array backends; its promotion rules then apply rather than numpy’s. Reductions the standard cannot express, such as the minimum of a boolean array, are applied by numpy and converted back.
Parameters
| Parameter | Description |
|---|---|
| name | The name of the reduction; one of min, max, mean, std, or sum. |
| array | The array to reduce. |
| axis | The axis, or axes, to reduce along. If None, reduce all of them. |
| keepdims | If True, leave the reduced axes in the output with length one. |