MathGroup Archive 2004

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

Search the Archive

Re: argMax

  • To: mathgroup at
  • Subject: [mg51270] Re: argMax
  • From: "Peltio" <peltio at>
  • Date: Mon, 11 Oct 2004 01:25:29 -0400 (EDT)
  • References: <ckaj3i$m3r$>
  • Reply-to: "Peltio" <peltioNOSP at>
  • Sender: owner-wri-mathgroup at

"Pierre Albarede" wrote

>I miss a fast internal function ArgMax.
>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,
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

    ArgMax[f_, arglist_List] :=
        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] :=
        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,
Invalid address in reply-to. Crafty demunging required to mail me.

  • Prev by Date: Outer product in mathematica
  • Next by Date: Re: plotting groups of polynomial roots
  • Previous by thread: argMax
  • Next by thread: Re: Re: argMax