[Numpy-discussion] argmin & min on ndarrays
Tue Mar 4 15:31:51 CST 2008
Let a & b be two ndarrays of the same shape. I'm trying to find the elements
of b that correspond to the minima of a along an arbitrary axis.
The problem is trivial when axis=None or when a.ndim=2, but I'm getting
confused with higher dimensions: I came to the following solution that looks
rather ugly, and I'd need some ideas to simplify it
>>>b = numpy.rollaxis(a,axis,0)[a.argmin(axis)][tuple(*(a.ndim-1))]
Thanks a lot in advance for any suggestions.
More information about the Numpy-discussion