跳到内容

nanmax

沿着给定轴求最大值,跳过 NaN 值。默认使用所有轴。

参数

名称 类型 描述 默认值
x SparseArray

要执行约减操作的数组。

必需
axis 联合[int, Iterable[int]]

取最大值的轴。默认使用所有轴。

None
keepdims bool_

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

False
dtype dtype

输出数组的数据类型。

None

返回值

类型 描述
COO

归约后的稀疏输出数组。

另请参阅
源代码位于 sparse/numba_backend/_coo/common.py
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
def nanmax(x, axis=None, keepdims=False, dtype=None, out=None):
    """
    Maximize 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 maximize. 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.max`][] : Function without `NaN` skipping.
    - [`numpy.nanmax`][] : Equivalent Numpy function.
    """
    assert out is None
    x = asCOO(x, name="nanmax")

    ar = x.reduce(np.fmax, axis=axis, keepdims=keepdims, dtype=dtype)

    if (isscalar(ar) and np.isnan(ar)) or np.isnan(ar.data).any():
        warnings.warn("All-NaN slice encountered", RuntimeWarning, stacklevel=1)

    return ar