Re: Label of Max[list]
- To: mathgroup at smc.vnet.net
- Subject: [mg50205] Re: [mg50186] Label of Max[list]
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Fri, 20 Aug 2004 04:57:58 -0400 (EDT)
- Reply-to: hanlonr at cox.net
- Sender: owner-wri-mathgroup at wolfram.com
li=Table[Random[Integer,{1,3}],{10}]
{1, 2, 1, 3, 1, 2, 2, 3, 3, 3}
{m=Max[li],Flatten[Position[li, m]]}
{3, {4, 8, 9, 10}}
Bob Hanlon
>
> From: "Dr. Wolfgang Hintze" <weh at snafu.de>
To: mathgroup at smc.vnet.net
> Date: 2004/08/19 Thu AM 06:28:21 EDT
> To: mathgroup at smc.vnet.net
> Subject: [mg50205] [mg50186] Label of Max[list]
>
> 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
>
>