unravel_index in Python

unravel_index

Get the position of the biggest item in a multi-dimensional numpy array, use unravel_index.

https://stackoverflow.com/questions/3584243/get-the-position-of-the-biggest-item-in-a-multi-dimensional-numpy-array


In [170]: state
Out[170]:
array([[8, 5],
       [3, 2],
       [5, 1],
       [9, 6]])

In [171]: state.argmax()
Out[171]: 6

In [172]: maxidx = state.argmax()

In [173]: np.unravel_index(maxidx, state.shape)
Out[173]: (3, 0)