Skip to content

nanreduce

Performs an NaN skipping reduction on this array. See the documentation on sparse.COO.reduce for examples.

Parameters:

Name Type Description Default
x COO

The array to reduce.

required
method ufunc

The method to use for performing the reduction.

required
identity number

The identity value for this reduction. Inferred from method if not given. Note that some ufunc objects don't have this, so it may be necessary to give it.

None
axis Union[int, Iterable[int]]

The axes along which to perform the reduction. Uses all axes by default.

None
keepdims bool_

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

False
**kwargs dict

Any extra arguments to pass to the reduction operation.

{}

Returns:

Type Description
COO

The result of the reduction operation.

Raises:

Type Description
ValueError

If reducing an all-zero axis would produce a nonzero result.

See Also

sparse.COO.reduce : Similar method without NaN skipping functionality.

Source code in sparse/numba_backend/_coo/common.py
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
def nanreduce(x, method, identity=None, axis=None, keepdims=False, **kwargs):
    """
    Performs an `NaN` skipping reduction on this array. See the documentation
    on [`sparse.COO.reduce`][] for examples.

    Parameters
    ----------
    x : COO
        The array to reduce.
    method : numpy.ufunc
        The method to use for performing the reduction.
    identity : numpy.number
        The identity value for this reduction. Inferred from ``method`` if not given.
        Note that some ``ufunc`` objects don't have this, so it may be necessary to give it.
    axis : Union[int, Iterable[int]], optional
        The axes along which to perform the reduction. Uses all axes by default.
    keepdims : bool, optional
        Whether or not to keep the dimensions of the original array.
    **kwargs : dict
        Any extra arguments to pass to the reduction operation.

    Returns
    -------
    COO
        The result of the reduction operation.

    Raises
    ------
    ValueError
        If reducing an all-zero axis would produce a nonzero result.

    See Also
    --------
    [`sparse.COO.reduce`][] : Similar method without `NaN` skipping functionality.
    """
    arr = _replace_nan(x, method.identity if identity is None else identity)
    return arr.reduce(method, axis, keepdims, **kwargs)