mds_array_manipulation.argmax

Module Contents

Functions

argmax(→ Union[int, numpy.ndarray])

Returns the indices of the maximum values along an axis from the given array.

mds_array_manipulation.argmax.argmax(arr: numpy.ndarray, axis: int | None = None) int | numpy.ndarray[source]

Returns the indices of the maximum values along an axis from the given array.

Parameters:
  • arr (numpy.ndarray) – Input array.

  • axis (int, optional) – Axis along which to operate. By default, flattened input is used.

Returns:

indices – Indices of the maximum values along the specified axis.

Return type:

int or numpy.ndarray

Raises:
  • TypeError – If the input is not a numpy array.

  • ValueError – If the input array is empty, or the axis specified is greater than the number of dimensions.

Notes

If there are multiple occurrences of the maximum values, the indices corresponding to the first occurrence are returned.

Examples

>>> import numpy as np
>>> from mds_array_manipulation.mds_array_manipulation import argmax
>>> a = np.arange(6).reshape(2, 3)
>>> a
array([[0, 1, 2],
       [3, 4, 5]])
>>> argmax(a)
5
>>> argmax(a, axis=0)
array([1, 1, 1])
>>> argmax(a, axis=1)
array([2, 2])
>>> b = np.arange(6)
>>> b[1] = 5
>>> b
array([0, 5, 2, 3, 4, 5])
>>> argmax(b)  # Only the first occurrence is returned.
1