I have a list and I know the maximum value of that list by using Max[list]. The thing is I want to find out the index number of this list that corresponds to this value. For example:

c= f[Max[list]]

where the function f gives me the index of list that corresponds to the value Max[list] which is 9000 in this case. Maybe using Pick somehow. Since I am dealing with frequency spectrum, and I know that the maximum is near a low frequency, I would like for the function to just check the first few or so instead of all elements in list.

  • 2
    $\begingroup$ Have you seen Position[]? $\endgroup$ – J. M.'s technical difficulties Mar 13 '16 at 7:35
  • $\begingroup$ @J.M. I just did! Thanks! Anyone interested: f = {Max[#], Flatten[Position[#, Max[#]]][[1]]} &; where the output is in the form (***{ max value, index in list} ***) $\endgroup$ – phandaman Mar 13 '16 at 7:43

try this:

First@Flatten@Position[#, Max[#]] &@list


| improve this answer | |
  • 1
    $\begingroup$ Nice! Very similar implementation. I have been using Mathematica for well over a year now on and off and now only getting use to the Function and #& usage. I have been seeing a lot people on here using this @ I imagine its to do more than one function at a time. See my comment as well. $\endgroup$ – phandaman Mar 13 '16 at 7:45
  • 3
    $\begingroup$ The second argument of Ordering[] is quite convenient: Ordering[list, -1]. $\endgroup$ – J. M.'s technical difficulties Mar 13 '16 at 7:53
  • 1
    $\begingroup$ yes it took me some time to get a hang of the symbols too. The learning curve was steep i believe. &@ is as if you are saying apply a function on an argument, say (func &) and apply on something i.e. func&@something. And (Last@something) for instance means the same as Last[something ] $\endgroup$ – Ali Hashmi Mar 13 '16 at 7:53
  • $\begingroup$ @J.M. Spot on. I might change my code to use Ordering instead. $\endgroup$ – phandaman Mar 13 '16 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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