Andreas Mueller - 1 year ago 162

Python Question

I'm trying to get the indices of the maximum element in a Numpy array.

This can be done using

`numpy.argmax`

`numpy.argmax`

My problem is that using

`numpy.argmax`

`axis=None`

I could use

`divmod`

Answer Source

You could use `numpy.unravel_index()`

on the result of `numpy.argmax()`

:

```
>>> a = numpy.random.random((10, 10))
>>> numpy.unravel_index(a.argmax(), a.shape)
(6, 7)
>>> a[6, 7] == a.max()
True
```