# COO.max¶

COO.max(axis=None, keepdims=False, out=None)[source]

Maximize along the given axes. Uses all axes by default.

Parameters
• 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

The reduced output sparse array.

Return type

COO

numpy.max

Equivalent numpy function.

scipy.sparse.coo_matrix.max()

Equivalent Scipy function.

nanmax

Function with NaN skipping.

Notes

• This function internally calls COO.sum_duplicates to bring the array into canonical form.

Examples

You can use COO.max to maximize an array across any dimension.

>>> x = np.add.outer(np.arange(5), np.arange(5))
>>> x
array([[0, 1, 2, 3, 4],
[1, 2, 3, 4, 5],
[2, 3, 4, 5, 6],
[3, 4, 5, 6, 7],
[4, 5, 6, 7, 8]])
>>> s = COO.from_numpy(x)
>>> s2 = s.max(axis=1)
>>> s2.todense()
array([4, 5, 6, 7, 8])


You can also use the keepdims argument to keep the dimensions after the maximization.

>>> s3 = s.max(axis=1, keepdims=True)
>>> s3.shape
(5, 1)


By default, this reduces the array down to one number, maximizing along all axes.

>>> s.max()
8