[Numpy-discussion] [numpy] argmin in multidimensional arrays
Glen W. Mabey
Glen.Mabey at swri.org
Sat Mar 3 14:46:50 EST 2007
On Thu, 06 Jul 2006 04:59:22 -0600, Travis wrote:
> Subject: numpy : argmin in multidimensional arrays
>
> TG wrote:
> > Hi there.
> >
> > I am working with multi-dimensional arrays and I need to get
> > coordinates of the min value in it.
> >
> > using myarray.argmin() returns the index in the flatten array, which is
> > a first step, but I wonder if it is possible to get the coordinates
> > directly as an array, rather than calculating them myself by using this
> > flat index and the shape of the array.
> >
> > well, in fact i'm not sure to understand how argmin(myarray) works,
> > when myarray is multidimensional.
>
>
> By default, the argmin method flattens the array and returns the flat
> index. You can get the corresponding element using
>
> myarray.flat[index]
>
> Alternatively, you can use the function unravel_index
>
> unravel_index(flat_index, myarray.shape)
>
> to return an N-dimensional index.
<not_a_complaint>
Does anyone else find this behavior counter-intuitive?
It seems to me that one of the great design features of numpy is the
n-dim generality it provides, and argmin is one function in this breaks
down, IMHO.
</not_a_complaint>
Glen Mabey
More information about the NumPy-Discussion
mailing list