Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine Index of Highest Value in Python's NumPy

Tags:

python

numpy

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...

like image 841
Jonathan Avatar asked Nov 11 '10 00:11

Jonathan


People also ask

How do you find the index of a maximum value in NumPy?

argmax() in Python. The numpy. argmax() function returns indices of the max element of the array in a particular axis.

How do you find the index of a maximum value in Python?

Use the enumerate() function to find out the index of the maximum value in a list. Use the numpy. argmax() function of the NumPy library to find out the index of the maximum value in a list.

How do you find the largest element in a NumPy array?

Now try to find the maximum element. To do this we have to use numpy. max(“array name”) function. For finding the minimum element use numpy.

How do you find the index of a NumPy array?

Using ndenumerate() function to find the Index of value It is usually used to find the first occurrence of the element in the given numpy array.


1 Answers

The argmax() function does do what you want:

print a.argmax(axis=1)
array([2, 0, 1])
like image 95
Sven Marnach Avatar answered Sep 28 '22 17:09

Sven Marnach