Skip to content

nansum

Performs a NaN skipping sum operation along the given axes. Uses all axes by default.

Parameters:

Name Type Description Default
x SparseArray

The array to perform the reduction on.

required
axis Union[int, Iterable[int]]

The axes along which to sum. Uses all axes by default.

None
keepdims bool_

Whether or not to keep the dimensions of the original array.

False
dtype dtype

The data type of the output array.

None

Returns:

Type Description
COO

The reduced output sparse array.

See Also
Source code in sparse/numba_backend/_coo/common.py
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
def nansum(x, axis=None, keepdims=False, dtype=None, out=None):
    """
    Performs a ``NaN`` skipping sum operation along the given axes. Uses all axes by default.

    Parameters
    ----------
    x : SparseArray
        The array to perform the reduction on.
    axis : Union[int, Iterable[int]], optional
        The axes along which to sum. Uses all axes by default.
    keepdims : bool, optional
        Whether or not to keep the dimensions of the original array.
    dtype : numpy.dtype
        The data type of the output array.

    Returns
    -------
    COO
        The reduced output sparse array.

    See Also
    --------
    - [`sparse.COO.sum`][] : Function without ``NaN`` skipping.
    - [`numpy.nansum`][] : Equivalent Numpy function.
    """
    assert out is None
    x = asCOO(x, name="nansum")
    return nanreduce(x, np.add, axis=axis, keepdims=keepdims, dtype=dtype)