Andreas Mueller - 2 months ago 18

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

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
```

Source (Stackoverflow)

Comments