Numpy Max python

is there a way to get the index of the maximum element in python?

in matlab we have [V,I] = max(a,[],3) it will give us all the matrices along the axis 3 and the index of each max element. is there a way to do it in Python???
dadadudeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

yuk99Commented:
You can use ARGMAX to get index of maximum value in an array. Use axis parameter to select dimension. Remember, that Python has 0-based indexing and in 3D array pages go first, then rows, then columns.

>>> from numpy import *
>>> from numpy.random import *
>>> a=rand(2,3,4)
>>> a
array([[[ 0.77719312,  0.07528051,  0.329186  ,  0.57896034],
        [ 0.23969721,  0.84188311,  0.03823846,  0.00302184],
        [ 0.3186661 ,  0.56970729,  0.42438946,  0.93728107]],

       [[ 0.50081337,  0.31282687,  0.973639  ,  0.9663504 ],
        [ 0.96829553,  0.47095946,  0.55364473,  0.4134808 ],
        [ 0.86336784,  0.18058616,  0.82078642,  0.35064008]]])
>>> a.max(axis=0)
array([[ 0.77719312,  0.31282687,  0.973639  ,  0.9663504 ],
       [ 0.96829553,  0.84188311,  0.55364473,  0.4134808 ],
       [ 0.86336784,  0.56970729,  0.82078642,  0.93728107]])
>>> ind = a.argmax(axis=0)
>>> ind
array([[0, 1, 1, 1],
       [1, 0, 1, 1],
       [1, 0, 1, 0]])

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dadadudeAuthor Commented:
Great answer. Thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.