6

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:

array([[119., 323.,  42., 277., 401.],
       [122., 326.,  39., 278., 10.],
       [125., 329.,  36., 12., 407.],
       ...,
       [308., 314., 469., 188., 266.],
       [308., 314., 469., 188., 266.],
       [308., 314., 469., 188., 266.]])

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:

np.where(array == array.min())

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

1
  • indexes = [x.index(min(x)) for x in the_array] Commented Mar 11, 2019 at 18:46

1 Answer 1

12

Use numpy argmin():

np.argmin(a, axis=1)

where a is your numpy array.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.