Numpy minimum in (row, column) format

yassin picture yassin · Jul 12, 2010 · Viewed 28.6k times · Source

How can I know the (row, column) index of the minimum of a numpy array/matrix?

For example, if A = array([[1, 2], [3, 0]]), I want to get (1, 1)

Thanks!

Answer

Philipp picture Philipp · Jul 12, 2010

Use unravel_index:

numpy.unravel_index(A.argmin(), A.shape)