Numpy minimum in (row, column) format Numpy minimum in (row, column) format python python

Numpy minimum in (row, column) format


Use unravel_index:

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


[Corrected typo]

Another simple solution is

ri, ci = A.argmin()//A.shape[1], A.argmin()%A.shape[1]

As numpy.argmin returns the index reading in row-major order


Yes, you are right, it was a typo, which worked for square matrix