Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numpy minimum in (row, column) format

People also ask

How does NumPy calculate min?

minimum() function is used to find the element-wise minimum of array elements. It compare two arrays and returns a new array containing the element-wise minima. If one of the elements being compared is a NaN, then that element is returned.

How do you find the minimum value of a 2d array NumPy?

min to return the minimum value, or equivalently for an array arrname use arrname. min() . As you mentioned, numpy. argmin returns the index of the minimum value (of course, you can then use this index to return the minimum value by indexing your array with it).


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