MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How to find the index of a maximal element in a list?


Valter Sorana wrote:

>I may have a mental block, but I cannot find anything better than
>
>Position[listName,Max[listName]]
>
>that traverses the list twice - once to find the maximum and once to find where it is.
>
>Isn't there a way to get both the index and the max value in one go?
>
>(of course one could write a loop that does this, but I want to avoid loops)
>
>Thanks,
>
>Valter.
>  
>
Use Ordering:

lst={1,2,10,2};

Ordering[lst,-1]
{3}

Finding the max value using Part once the index is known is practically 
instantaneous.

Carl Woll
Wolfram Research


  • Prev by Date: Re: Re: pdf
  • Next by Date: Re: How to find the index of a maximal element in a list?
  • Previous by thread: How to find the index of a maximal element in a list?
  • Next by thread: Re: How to find the index of a maximal element in a list?