'How to get the index of the max value of each list in the array?
So I have this array,
a = np.array([[5,10,1,3], [1,5,1,5], [0,3,1,8]])
and I wish to show the index of the max value of each. the output will be shown like this
'1,1,3'
as 5 is the max value of the 1st element and it's index is 1, as 5 is the max value of the 1st element and it's index is 1, and as 8 is the max value of the 1st element and it's index is 3.
I have tried some function, like max and do the looping, and argmax, but I couldn't find the right answer. I am really new to python.
please help me with the function that can return the output regardless the length of the array. Thank you..
Solution 1:[1]
Your idea works fine for me:
a.argmax(axis=1)
yields:
Out[]: array([1, 1, 3])
same for np.argmax(a,axis=1)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Flag |
