argMax
- To: mathgroup at smc.vnet.net
- Subject: [mg51243] argMax
- From: Pierre Albarede <pa.news at free.fr>
- Date: Sun, 10 Oct 2004 01:57:14 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Hi,
I miss a fast internal function ArgMax. Sure, it is easily programmed,
for example,
argMaxMax[function1_, list1_List] := With[
{max1 = Max[function1 /@ list1]},
{Select[list1, function1[#] == max1 &], max1}
]
argMax = Composition[First, argMaxMax]
or
argMaxMax1[function1_, list1_List] := With[
{h = MapIndexed[{function1@#1, #2} &, list1]},
With[
{max1 = Max[First /@ h]},
{Extract[list1, Last /@ Select[h, First@# == max1 &]], max1}
]
]
argMax = Composition[First, argMaxMax1]
but this will be much slower that Max. How can I have a faster argMax ?
Thanks.