[Numpy-discussion] maximum value and corresponding index

David Goldsmith d_l_goldsmith@yahoo....
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
(2, 3)

DG

--- On Wed, 8/5/09, Robert Kern <robert.kern@gmail.com> wrote:

> From: Robert Kern <robert.kern@gmail.com>
> Subject: Re: [Numpy-discussion] maximum value and corresponding index
> To: "Discussion of Numerical Python" <numpy-discussion@scipy.org>
> Date: Wednesday, August 5, 2009, 12:59 PM
> On Wed, Aug 5, 2009 at 14:57, Dr.
> Phillip M.
> Feldman<pfeldman@verizon.net>
> wrote:
> >
> > 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
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
> 


      


More information about the NumPy-Discussion mailing list