[Tutor] Finding the minimum value in a multidimensional array

Jerry Hill malaclypse2 at gmail.com
Tue Mar 13 15:00:05 CET 2007


On 3/13/07, Geoframer <geoframer at gmail.com> wrote:
> I don't see a solution here... It is not conclusive on what's the minimum
> for an array.
>
> ln [1]: import numpy
>  In [2]: a =
> numpy.array([[1,2,3,0],[2,3,4,5],[6,5,4,3],[-1,2,-4,5]])

Well, what exactly is it that you'd like the answer to be?  The
samples page Eike pointed you to show a couple of ways to do it,
depending on exactly what piece of data you're looking for.  Here's a
bit more along the same lines.  If this doesn't help, perhaps you
could show us a bit of sample data and tell us exactly what answer
you'd like to extract.

>>> a = numpy.array([[1,2,3,0],[2,3,4,5],[6,5,4,3],[-1,2,-4,5]])
>>> a.argmin()
14
>>> a.ravel()[14]
-4
>>> divmod(14, 4)
(3, 2)
>>> a[3][2]
-4

-- 
Jerry


More information about the Tutor mailing list