Skip to content

nanprod

Performs a product operation along the given axes, skipping NaN values. 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 multiply. 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
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
def nanprod(x, axis=None, keepdims=False, dtype=None, out=None):
    """
    Performs a product operation along the given axes, skipping `NaN` values.
    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 multiply. 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.prod`][] : Function without `NaN` skipping.
    - [`numpy.nanprod`][] : Equivalent Numpy function.
    """
    assert out is None
    x = asCOO(x)
    return nanreduce(x, np.multiply, axis=axis, keepdims=keepdims, dtype=dtype)