[Numpy-discussion] numpy.ma.arg{min,max}
Adam Oliner
oliner@stanford....
Fri Apr 10 17:46:35 CDT 2009
Christoper,
I see, thanks. Then the documentation should say that it returns an
array of the _smallest_ indices of the minimum values along the given
axis.
If the minimum value is not unique, as in my examples, is there an
efficient way to get all of these indices? It seems that I can get
roughly the behavior I want with 'where':
>>> a
array([1, 1, 1, 5, 5])
>>> numpy.ma.where(a==numpy.ma.max(a))[0]
array([3, 4])
>>> numpy.ma.where(a==numpy.ma.min(a))[0]
array([0, 1, 2])
- Adam J. Oliner
oliner@cs.stanford.edu
On Apr 10, 2009, at 3:16 PM, Christopher Barker wrote:
> Adam Oliner wrote:
>> The documentation for numpy.ma.argmin says:
>> "Returns array of indices of the maximum values along the given
>> axis."
>>
>> Aside from probably meaning to say the 'minimum' values,
>
> that's a typo...
>
>
>> it also doesn't seem to return an array:
>
> it does if you use a higher rank array, and specify an axis:
>
>>>> a
> array([[ 0.643502 , 0.83867769, 0.97762954, 0.49686553],
> [ 0.37798796, 0.69300396, 0.06683333, 0.3457077 ],
> [ 0.51357262, 0.29095034, 0.42811108, 0.72644421],
> [ 0.5977396 , 0.64992292, 0.53068753, 0.46386281]])
>
>>>> np.argmin(a, 0)
> array([1, 2, 1, 1])
>
>>>> np.argmin(a, 1)
>
> array([3, 2, 1, 3])
>
>
> argmin(a, axis=None)
> Return array of indices to the minimum values along the given
> axis.
>
> Parameters
> ----------
> a : {array_like}
> Array to look in.
> axis : {None, integer}
> If None, the index is into the flattened array, otherwise
> along
> the specified axis
>
>
>
>
> --
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R (206) 526-6959 voice
> 7600 Sand Point Way NE (206) 526-6329 fax
> Seattle, WA 98115 (206) 526-6317 main reception
>
> Chris.Barker@noaa.gov
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
More information about the Numpy-discussion
mailing list