Retrieving minimum indices in a numpy array

There are many similar questions, but none of them seemed to help me. I want to return indexes for the minimum value in a numpy array. Let's say, for example, the array was:

[[4,3,5,1]
 [2,6,5,1]
 [8,3,2,4]]

I want my program to return (0.3). I tried using argmin but did not succeed.

Note that I only want to return one set of indices. IE is not (0.3) And (1.3) in the above example.

Any help would be greatly appreciated

Jack

+4
source share
1 answer

Use unravel_index:

arr = np.array([[4,3,5,1],[2,6,5,1],[8,3,2,4]])
index = np.unravel_index(arr.argmin(), arr.shape)
# (0, 3)
+6
source

Source: https://habr.com/ru/post/1660836/


All Articles