I have spent the last hour trying to figure this out
Suppose we have
import numpy as np
a = np.random.rand(5, 20) - 0.5
amin_index = np.argmin(np.abs(a), axis=1)
> [ 0 12 5 18 1] # or something similar
One way is to pass in the array of row indexes (e.g.
[0,1,2,3,4]) and the list of column indexes for the minimum in each corresponding row (your list
This returns an array containing the value at
[i, amin_index[i]] for each row
>>> a[np.arange(a.shape), amin_index] array([-0.0069325 , 0.04268358, -0.00128002, -0.01185333, -0.00389487])
This is basic indexing (rather than advanced indexing), so the returned array is actually a view of
a rather than a new array in memory.