[Numpy-discussion] Selecting columns of a matrix (original) (raw)
Pau Gargallo pau.gargallo at gmail.com
Wed Jun 21 13:31:48 EDT 2006
- Previous message (by thread): [Numpy-discussion] Selecting columns of a matrix
- Next message (by thread): [Numpy-discussion] Selecting columns of a matrix
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 6/21/06, Travis Oliphant <oliphant.travis at ieee.org> wrote:
Pau Gargallo wrote: > On 6/21/06, Travis Oliphant <oliphant.travis at ieee.org> wrote: > >> Johannes Loehnert wrote: >> >>> Hi, >>> >>> >>> >>>> I'm not sure why bool arrays cannot be used as indices. >>>> The "natural" solution to the original problem seemed to be: >>>> M[:,V>0] >>>> but this is not allowed. >>>> >>>> >>> I started a thread on this earlier this year. Try searching the archive for >>> "boolean indexing" (if it comes back online somewhen). >>> >>> Travis had some reason for not implementing this, but unfortunately I do not >>> remember what it was. The corresponding message might still linger on my home >>> >>> PC, which I can access this evening.... >>> >>> >> I suspect my reason was just not being sure if it could be explained >> consistently. But, after seeing this come up again. I decided it was >> easy enough to implement. >> >> So, in SVN NumPy, you will be able to do >> >> a[:,V>0] >> a[V>0,:] >> >> The V>0 will be replaced with integer arrays as if nonzero(V>0) had been >> called. >> >> > > does it work for a[,] ? > Sure, it will work. Basically all boolean arrays will be interpreted as nonzero(V>0), everywhere. > what about a[ix( nonzero(), nonzero() )] ? > > maybe the to nonzero() conversion would be more > coherently done by the ix function than by the [] > > I've just added support for inside ix so that the nonzero will be done automatically as well.
So a[ix(,)] will give the cross-product selection.
ok so: a[ b1, b2 ] will be different than a[ ix_(b1,b2) ] just like with integer indices. Make sense to me.
also, a[b] will be as before (a[where(b)]) ? maybe a trailing coma could lunch the new behaviour? a[b] -> a[where(b)] a[b,] -> a[b,...] -> a[nonzero(b)]
Thanks,
pau
- Previous message (by thread): [Numpy-discussion] Selecting columns of a matrix
- Next message (by thread): [Numpy-discussion] Selecting columns of a matrix
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]