跳到内容

argmax

返回沿指定轴的最大值的索引。当最大值出现多次时,只返回第一次出现对应的索引。

参数

名称 类型 描述 默认值
x SparseArray

输入数组。填充值必须为 0.0,所有非零值必须大于 0.0

必需
axis int

要搜索的轴。如果为 None,函数必须返回扁平化数组中最大值的索引。默认值:None

None
keepdims bool_

如果为 True,缩减的轴(维度)必须作为单例维度包含在结果中,并且结果必须与输入数组兼容。否则,如果为 False,缩减的轴(维度)不得包含在结果中。默认值:False

False

返回值

名称 类型 描述
out ndarray

如果 axisNone,则为包含最大值第一次出现索引的零维数组。否则,为包含最大值索引的非零维数组。

源代码位于 sparse/numba_backend/_coo/common.py
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
def argmax(x, /, *, axis=None, keepdims=False):
    """
    Returns the indices of the maximum values along a specified axis.
    When the maximum value occurs multiple times, only the indices
    corresponding to the first occurrence are returned.

    Parameters
    ----------
    x : SparseArray
        Input array. The fill value must be ``0.0`` and all non-zero values
        must be greater than ``0.0``.
    axis : int, optional
        Axis along which to search. If ``None``, the function must return
        the index of the maximum value of the flattened array. Default: ``None``.
    keepdims : bool, optional
        If ``True``, the reduced axes (dimensions) must be included in the result
        as singleton dimensions, and, accordingly, the result must be compatible
        with the input array. Otherwise, if ``False``, the reduced axes (dimensions)
        must not be included in the result. Default: ``False``.

    Returns
    -------
    out : numpy.ndarray
        If ``axis`` is ``None``, a zero-dimensional array containing the index of
        the first occurrence of the maximum value. Otherwise, a non-zero-dimensional
        array containing the indices of the maximum values.
    """
    return _arg_minmax_common(x, axis=axis, keepdims=keepdims, mode="max")