Re: argMax
- To: mathgroup at smc.vnet.net
- Subject: [mg51270] Re: argMax
- From: "Peltio" <peltio at twilight.zone>
- Date: Mon, 11 Oct 2004 01:25:29 -0400 (EDT)
- References: <ckaj3i$m3r$1@smc.vnet.net>
- Reply-to: "Peltio" <peltioNOSP at Mdespammed.com.invalid>
- Sender: owner-wri-mathgroup at wolfram.com
"Pierre Albarede" wrote >I miss a fast internal function ArgMax. [snip] >but this will be much slower that Max. How can I have a faster argMax ? I've written this without any testing, so I can't tell whether it's faster or not than your solution (if it happens to be so, it won't be much faster, though). You can either have a version of ArgMax that works for onedimensional lists giving you a list of the elements that produce a max (you can have more than one)... ArgMax[f_, arglist_List] := Module[ {spectrum}, spectrum = f /@ arglist; Flatten[Take[arglist, #] & /@ Position[spectrum, Max[spectrum]]] ] Or a multidimensional one, that can give you a list of coordinates of the points giving you a max. ArgMax[f_, arglist_List] := Module[ {spectrum}, spectrum = Map[f, arglist, -1]; Take[arglist, #] & /@ Position[spectrum, Max[spectrum]] ] (pattern matching can be adopted to have the proc automatically choose the code to be employed). hope this helps, Peltio -- Invalid address in reply-to. Crafty demunging required to mail me.
- Follow-Ups:
- Re: Re: argMax
- From: DrBob <drbob@bigfoot.com>
- Re: Re: argMax