bundles / numpy 2.4.4 / numpy / nancumsum
_ArrayFunctionDispatcher
numpy:nancumsum
Signature
def nancumsum ( a , axis = None , dtype = None , out = None ) Summary
Return the cumulative sum of array elements over a given axis treating Not a Numbers (NaNs) as zero. The cumulative sum does not change when NaNs are encountered and leading NaNs are replaced by zeros.
Extended Summary
Zeros are returned for slices that are all-NaN or empty.
Parameters
a: array_likeInput array.
axis: int, optionalAxis along which the cumulative sum is computed. The default (None) is to compute the cumsum over the flattened array.
dtype: dtype, optionalType of the returned array and of the accumulator in which the elements are summed. If
dtypeis not specified, it defaults to the dtype ofa, unlessahas an integer dtype with a precision less than that of the default platform integer. In that case, the default platform integer is used.out: ndarray, optionalAlternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. See
ufuncs-output-typefor more details.
Returns
nancumsum: ndarray.A new array holding the result is returned unless
outis specified, in which it is returned. The result has the same size asa, and the same shape asaifaxisis not None orais a 1-d array.
Examples
import numpy as np np.nancumsum(1) np.nancumsum([1])✓
np.nancumsum([1, np.nan])
✗a = np.array([[1, 2], [3, np.nan]])
✓np.nancumsum(a) np.nancumsum(a, axis=0) np.nancumsum(a, axis=1)✗
See also
- isnan
Show which elements are NaN.
- numpy.cumsum
Cumulative sum across array propagating NaNs.
Aliases
-
numpy.nancumsum