Skip to content
Advertisement

Finding the index of minimum value in a row in numpy array

I can’t seem to get my head around how to do this – I am new to Python and this kind of work with arrays. I have a large array, say:

JavaScript

I would like to find the column index of the minimum value in each row. For instance for the first 3 rows would give [2, 4, 3….]. I have experimented with .min() and np.where(), for instance:

JavaScript

But I just can’t seem to get the answer I’m looking for. Any help would be much appreciated, thanks

Advertisement

Answer

Use numpy argmin():

JavaScript

where a is your numpy array.

Advertisement