11

I want to generate an array with the index of the highest max value of each row.

a = np.array([ [1,2,3], [6,5,4], [0,1,0] ])
maxIndexArray = getMaxIndexOnEachRow(a)
print maxIndexArray 

[[2], [0], [1]]

There's a np.argmax function but it doesn't appear to do what I want...

1 Answer 1

20

The argmax() function does do what you want:

print a.argmax(axis=1)
array([2, 0, 1])
Sign up to request clarification or add additional context in comments.

1 Comment

This also exists as a top level function, thus the following also works: maxvals = np.argmax(a, axis=1)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.