[Numpy-discussion] how to use argsort result?
Pau Gargallo
pau.gargallo at gmail.com
Thu Jul 13 04:35:33 EDT 2006
On 7/12/06, Victoria G. Laidler <laidler at stsci.edu> wrote:
> Hi,
>
> Pardon me if I'm reprising an earlier discussion, as I'm new to the list.
>
> But is there a reason that this obscure syntax
>
> A[arange(2)[:,newaxis],indexes]
>
> A[arange(A.shape[0])[:,newaxis],indexes]
>
> is preferable to the intuitively reasonable thing that the Original
> Poster did?
>
> A[indexes]
>
i don't think so.
The obscure syntax is just a way you can solve the problem with the
current state of NumPy. Of course, a more clearer syntax would be
better, but for this, something in NumPy should be changed.
This other syntax is longer but clearer:
ind = indices(A.shape)
ind[ax] = A.argsort(axis=ax)
A[ind]
Which brings me to the question:
Would it be reasonable if argsort returned the complete tuple of
indices, so that
A[A.argsort(ax)] would work ?
pau
More information about the NumPy-Discussion
mailing list