跳到内容

nanreduce

对此数组执行跳过NaN的归约操作。有关示例,请参阅sparse.COO.reduce的文档。

参数

名称 类型 描述 默认值
x COO

要归约的数组。

必需
method ufunc

用于执行归约的方法。

必需
identity number

此归约的恒等值。如果未给出,则从method推断。请注意,某些ufunc对象没有此值,因此可能需要指定它。

None
axis 联合[int, 可迭代对象[int]]

执行归约的轴。默认使用所有轴。

None
keepdims bool_

是否保留原始数组的维度。

False
**kwargs dict

传递给归约操作的任何额外参数。

{}

返回值

类型 描述
COO

归约操作的结果。

引发

类型 描述
ValueError

如果对全零轴进行归约会产生非零结果。

另请参阅

sparse.COO.reduce :类似方法,但不具有跳过NaN的功能。

源代码位于 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)