Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

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

Search the Archive

Re: Greatest element in list

  • To: mathgroup at
  • Subject: [mg30491] Re: Greatest element in list
  • From: Jens-Peer Kuska <kuska at>
  • Date: Fri, 24 Aug 2001 04:05:51 -0400 (EDT)
  • Organization: Universitaet Leipzig
  • References: <9m27in$gqd$>
  • Sender: owner-wri-mathgroup at


without your data I can't reproduce the problem.

MaxPosition = Compile[{{lst, _Real, 1}}, Module[{max = First[lst], pos =
1, i = 2},
        If[# > max, max = #; pos = i++, i++] & ,

is atleast faster than Position[#, Max[#]] &[lst]

In[]:=lst = Table[Random[], {1000000}];

In[]:=Timing[Position[#, Max[#]] &[lst]]
Out[]={6.85 Second, {{602020}}}

Out[]={4.42 Second, 602020}

Because it scans the list only once.


Oliver Friedrich wrote:
> Hi,
> what's the best way to get the position of the greatest number in list of
> reals? I've tried
> Position[#,Max[#]]&list
> but surprisingly, it doesn't work all the time, sometimes it returns an
> empty list. How is that, because a theorem says that a non empty set of real
> numbers must have at least one biggest element. So Max[#] can't be empty.
> Any solutions ?
> Oliver Friedrich

  • Prev by Date: Re: Greatest element in list
  • Next by Date: RE: Greatest element in list
  • Previous by thread: Re: Greatest element in list
  • Next by thread: RE: Greatest element in list