This question already has an answer here:

Let's suppose that I have table t = {1.23, 3.4, 10, 34, 1.78, 0.98, 12.56}. To take the biggest element I can use Max[t] function. But I want to take not only the maximum element, but also the index of the element (so, which element in table it is). Is any function which helps to take the indes of element, when I know the value of this element?


marked as duplicate by Mr.Wizard Jan 22 '14 at 23:30

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.

  • 8
    $\begingroup$ Position[t,Max[t]] $\endgroup$ – ciao Jan 22 '14 at 22:24
  • 1
  • $\begingroup$ I am closing this as a duplicate, for now. There are a number of similar questions on this site that can be found by searching for Position, Ordering, etc. Several deal specifically with maximum values. Also, your question is not fully specified; do you want only the position of one or all maximum values for example? Further, this question is arguably "easily found in the documentation" for Position. If you have a more specific question please edit accordingly. $\endgroup$ – Mr.Wizard Jan 22 '14 at 23:32
  • 1
    $\begingroup$ @Ziva my closing this question was not meant to chastise you for asking; rather it is to keep the site organized to the extend that I am able. I know that the documentation can be hard to navigate. Searching this site is hopefully a bit easier, and every duplicate question provides another avenue to find what one is looking for, e.g. this one now uses the terminology "index" and in addition to Sjoerd's answer it points to two more questions which are hopefully helpful. (continued) $\endgroup$ – Mr.Wizard Jan 23 '14 at 2:57
  • 1
    $\begingroup$ For the documentation itself you could conceivably have found Position by searching for "index" the second result of which is the page for StringPosition, and the first link under "See Also" on that page is to Position. Convoluted, I know, but that's fairly common, so if you want to learn to use the documentation I suggest getting used to it. Another search term that would have been more direct is "Find" the second result for which is Position. $\endgroup$ – Mr.Wizard Jan 23 '14 at 3:02
Ordering[t, -1]  

which is orders of magnitude faster than

  • $\begingroup$ Since the op states after initial example " Is any function which helps to take the indes of element, when I know the value of this element?", a much more general statement, not sure ordering will address it. Of course, if one is only after the last instance of a maximum (because if there are multiple, ordering again becomes a bit useless), this is the fastest way. $\endgroup$ – ciao Jan 22 '14 at 23:21
  • $\begingroup$ Make sure to actually get the max index out of the list that "Ordering" returns. Ordering[t,-1][[1]] $\endgroup$ – sffc Oct 14 '15 at 21:27
  • $\begingroup$ Ah, yes, of course. $\endgroup$ – Sjoerd C. de Vries Oct 14 '15 at 21:53

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