[Numpy-discussion] max argmax combo

Bill Baxter wbaxter at gmail.com
Tue Sep 19 14:41:56 CDT 2006


On 9/20/06, Francesc Altet <faltet at carabos.com> wrote:
> A Dimarts 19 Setembre 2006 19:21, Charles R Harris va escriure:
> >
> > Do you want both the indexes and index sorted array returned, or just sort
> > the array using indexes, i.e., something like
> >
> > a.sort(kind="quicksort", method="indirect")
>
> Uh, I don't understand what do you mean by "sort the array using indexes",
> sorry.
>

I think he meant do an argsort first, then use fancy indexing to get
the sorted array.
For a 1-d array that's just

  ind = A.argsort()
  Asorted = A[ind]

That should be O(N lg N + N), aka O(N lg N)
For A >1-d, you need an indexing expression that's a little more
complicated, hence the discussion about making an "extract" function
for that purpose.  Then you could say:

  ind = A.argsort(axis=d)
  Asorted = A.extract(ind,axis=d)

and it should just work no matter what 'd' is.

--bb




More information about the Numpy-discussion mailing list