Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

We can use Max[exampleList] or Min[exampleList] to find the maxima and minima of exampleList, however, is there a similar standalone function that returns something like {position in array, maximum value in the array} or {position in array, minimum value in the array}, i.e. both the position and value of the maximum or minimum element in exampleList? It seems awkward to have to write Position[exampleList,Max[exampleList]] or Position[exampleList,Min[exampleList]]?

share|improve this question

marked as duplicate by Sjoerd C. de Vries, Mr.Wizard Apr 9 at 9:56

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2  
Take a look at reference.wolfram.com/mathematica/ref/Ordering.html for the position. –  blochwave Apr 9 at 8:55
    
@blochwave Yes, thank you, that's what I was looking for. –  Geof Apr 9 at 9:00
    
Related: (900), (1342), (2177) –  Mr.Wizard Apr 9 at 9:57
add comment

1 Answer 1

up vote 1 down vote accepted
Position[list,_?(#==Max[list]&)]

or shorter (per your comment...)

Position[list,Max[list]]

will do the trick, obviously change Max to Min for minimum...

Or, as suggested in comments

Ordering[list,1]
Ordering[list,-1]

Will give positions of minimum and maximum, respectively.

share|improve this answer
    
Why can't we just write Position[exampleList,Max[exampleList]]? Sorry, I wrote that just as you were posting this answer. –  Geof Apr 9 at 8:56
    
@Geof: Well, for one thing, that's incomplete. The first argument to Position is the target list, and Max does not return a list... –  rasher Apr 9 at 8:57
    
OK, I like the use of Ordering here, that's what I was after! –  Geof Apr 9 at 8:58
    
Sorry, that was a typo, I fixed the comment. I meant, why can't "(#==Max[list]&)" just be "Max[exampleList]"? –  Geof Apr 9 at 8:58
    
@geof: you can, I'm just in the habit of having complex functions there... –  rasher Apr 9 at 8:59
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.