From: Pau G. <pau...@gm...> - 2006-07-13 12:09:10
|
On 7/13/06, Travis Oliphant <oli...@ie...> wrote: > Pau Gargallo wrote: > > On 7/12/06, Victoria G. Laidler <la...@st...> 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 ? > > > > > I think this is reasonable. We would need a way for the argsort() > function to work as it does now. I'm not sure if anybody actually uses > the multidimensional behavior of argsort now, but it's been in Numeric > for a long time. > actually I use the multidimensional behavior of argmin and argmax in its current state, and found it useful as it is, even if A[A.argmax(ax)] doesn't work. May be a keyword could be added, so that A.argxxx( axis=ax, indices=True ) returns the tuple of indices. (The keyword name and default should be discussed) I don't know if that's *the* way, but ... pau |