Re: Label of Max[list]
- To: mathgroup at smc.vnet.net
- Subject: [mg50221] Re: Label of Max[list]
- From: rknapp at wolfram.com (Rob Knapp)
- Date: Sat, 21 Aug 2004 03:04:24 -0400 (EDT)
- References: <cg20iv$os6$1@smc.vnet.net> <cg4f36$cdp$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
If, as the example indicates, the data consists of real numbers, whereMax[data_] := Module[{pos = Ordering[data, -1]}, {data[[pos[[1]]]], pos}] is orders of magnitude faster. If the data consists of Numeric quantities (e.g. Pi, E ...), then you can use the more general, but slower whereMaxNumeric[data_] := Module[{pos = Ordering[data, -1, Less]}, {data[[pos[[1]]]], pos}] If data is not a packed array, the numeric version is not a whole lot slower. Rob Knapp Jens-Peer Kuska <kuska at informatik.uni-leipzig.de> wrote in message news:<cg4f36$cdp$1 at smc.vnet.net>... > Hi, > > wehMax2[lst_] := > Module[{mm = Max[lst]}, > k = Position[lst, mm]; > {mm, k[[1]]} > ] > > should be a bit faster :-) > > Regards > Jens > > "Dr. Wolfgang Hintze" 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