[Tutor] Finding the minimum value in a multidimensional array
Geoframer
geoframer at gmail.com
Tue Mar 13 14:45:07 CET 2007
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]])
In [3]: a
Out[3]:
array([[ 1, 2, 3, 0],
[ 2, 3, 4, 5],
[ 6, 5, 4, 3],
[-1, 2, -4, 5]])
In [4]: a.argmin(0)
Out[4]: array([3, 0, 3, 0])
In [5]: a.argmin(1)
Out[5]: array([3, 0, 3, 2])
a.argmin(0) shows where the minimum is for each row
a.argmin(1) shows whree the minimum is for each column
Which combined gives (row, column) : (0,3), (1,0), (2,3) and (3,2). So
basically 4 values which i still need to compare. In a small array this
might not be a hefty computational effort. In a n*n array this will lead to
N values which need both indexing and comparing.
Perhaps this is the only solution around but i hope not. In either way
thanks for your time and suggestion.
Regards Geofram
On 3/13/07, Eike Welk <eike.welk at gmx.net> wrote:
>
> On Tuesday 13 March 2007 11:57, Geoframer wrote:
> > Hey everyone,
> >
> > I've been trying to locate a way to find the location of the
> > minimum value in an n*n array.
>
> The 'argmin' function is probably what you are looking for.
> See the examples at:
>
> http://www.scipy.org/Numpy_Example_List
>
> Regards Eike.
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070313/bae37e40/attachment.htm
More information about the Tutor
mailing list