Skip to content

max

Calculates the maximum value of the input array x.

Parameters:

Name Type Description Default
x

input array of a real-valued data type.

required
axis

axis or axes along which maximum values are computed. By default, the maximum value are computed over the entire array. If a tuple of integers, maximum values are computed over multiple axes. Default: None.

None
keepdims

If True, the reduced axes (dimensions) are included in the result as singleton dimensions. Accordingly, the result is compatible with the input array. Otherwise, if False, the reduced axes (dimensions) must not be included in the result. Default: False.

False

Returns:

Name Type Description
out array

if the maximum value was computed over the entire array, a zero-dimensional array containing the maximum value. Otherwise, a non-zero-dimensional array containing the maximum values. The returned array has the same data type as x.

Special Cases

For floating-point operands, if x_i is NaN, the maximum value is NaN (i.e., NaN values propagate).

Examples:

>>> a = sparse.COO.from_numpy(np.array([[0, 1], [2, 0]]))
>>> o = sparse.max(a, axis=1)
>>> o.todense()
array([1, 2])
Source code in sparse/numba_backend/_common.py
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
def max(x, /, *, axis=None, keepdims=False):
    """
    Calculates the maximum value of the input array ``x``.

    Parameters
    ----------
    x: array
        input array of a real-valued data type.
    axis: Optional[Union[int, Tuple[int, ...]]]
        axis or axes along which maximum values are computed.
        By default, the maximum value are computed over the entire array.
        If a tuple of integers, maximum values are computed over multiple axes. Default: ``None``.
    keepdims: bool
        If ``True``, the reduced axes (dimensions) are included in the result as singleton dimensions.
        Accordingly, the result is compatible with the input array.
        Otherwise, if ``False``, the reduced axes (dimensions) must not be included in the result. Default: ``False``.

    Returns
    -------
    out: array
        if the maximum value was computed over the entire array, a zero-dimensional array containing the maximum value.
        Otherwise, a non-zero-dimensional array containing the maximum values.
        The returned array has the same data type as ``x``.

    Special Cases
    -------------
    For floating-point operands, if ``x_i`` is ``NaN``, the maximum value is ``NaN`` (i.e., ``NaN`` values propagate).

    Examples
    --------
    >>> a = sparse.COO.from_numpy(np.array([[0, 1], [2, 0]]))
    >>> o = sparse.max(a, axis=1)
    >>> o.todense()
    array([1, 2])
    """
    return x.max(axis=axis, keepdims=keepdims)