[Numpy-discussion] maximum value and corresponding index
Wed Aug 5 15:06:03 CDT 2009
But you can "cheat" and put them on one line (if that's all you're after):
>>> x = np.array([1, 2, 3])
>>> maxi = x.argmax(); maxv = x[maxi]
>>> maxi, maxv
--- On Wed, 8/5/09, Robert Kern <firstname.lastname@example.org> wrote:
> From: Robert Kern <email@example.com>
> Subject: Re: [Numpy-discussion] maximum value and corresponding index
> To: "Discussion of Numerical Python" <firstname.lastname@example.org>
> Date: Wednesday, August 5, 2009, 12:59 PM
> On Wed, Aug 5, 2009 at 14:57, Dr.
> Phillip M.
> > With Python/NumPy, is there a way to get the maximum
> element of an array and
> > also the index of the element having that value, at a
> single shot?
> Not in one shot.
> maxi = x.argmax()
> maxv = x[maxi]
> Robert Kern
> "I have come to believe that the whole world is an enigma,
> a harmless
> enigma that is made terrible by our own mad attempt to
> interpret it as
> though it had an underlying truth."
> -- Umberto Eco
> NumPy-Discussion mailing list
More information about the NumPy-Discussion