MathGroup Archive 2004

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

Search the Archive

Re: Label of Max[list]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg50194] Re: [mg50186] Label of Max[list]
  • From: DrBob <drbob at bigfoot.com>
  • Date: Fri, 20 Aug 2004 04:57:29 -0400 (EDT)
  • References: <200408191028.GAA22901@smc.vnet.net>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

wehMax[li_] := {m = Max[li], Select[Range[Length[li]], li[[#1]] == m & ]}
myLabelMax[data_] :=
   Module[{max = Max[data]}, {max, Flatten[Position[data, max]]}]

test[n_] := Module[
    {data = RandomArray[BinomialDistribution[10, 0.3], {n}], one, two},
    one = Timing[wehMax[data]];
    two = Timing[myLabelMax[data]];
   {First[one], First[two], Last[one] == Last[two]}]

test[1000000]
{1.5779999999999994*Second, 0.09299999999999997*Second, True}

That's a timing for your method, then mine, and a test to see if they got the same answer.

Bobby

On Thu, 19 Aug 2004 06:28:21 -0400 (EDT), Dr. Wolfgang Hintze <weh at snafu.de> wrote:

> Is there a standard function providing beside the maximum of a list also
> the label(s) of the maximum?
>
> My solution is this
>
> In[23]:=
> wehMax[li_] := {m = Max[li], Select[Range[Length[li]],
>      li[[#1]] == m & ]}
>
> In[24]:=
> li = Table[Random[], {100}];
>
> In[25]:=
> wehMax[li]
>
> Out[25]=
> {0.9963517693166272, {89}}
>
> Is there a better one?
>
> Any hint appreciated.
>
> Wolfgang
>
>
>



-- 
DrBob at bigfoot.com
www.eclecticdreams.net


  • Prev by Date: 3D Screensavers for Mathematica users
  • Next by Date: Re: Hypergeometric function
  • Previous by thread: Re: Label of Max[list]
  • Next by thread: Re: Label of Max[list]