From: Travis O. <oli...@ie...> - 2006-05-18 16:40:25
|
Pau Gargallo wrote: > On 5/18/06, Bill Baxter <wb...@gm...> wrote: >> One thing I haven't quite managed to figure out yet, is what the heck >> indexing an array with an array is supposed to give you. >> This is sort of an offshoot of the "nonzero()" discussion. >> I was wondering why nonzero() and where() return tuples at all >> instead of >> just an array, till I tried it. >> >> >>> b >> array([[0, 1, 2], >> [3, 4, 5], >> [6, 7, 8]]) >> >>> b[ num.asarray(num.where(b>4)) ] >> array([[[3, 4, 5], >> [6, 7, 8], >> [6, 7, 8], >> [6, 7, 8]], >> >> [[6, 7, 8], >> [0, 1, 2], >> [3, 4, 5], >> [6, 7, 8]]]) >> >> Whoa, not sure what that is. Can someone explain the current rule >> and in >> what situations is it useful? I can't take too much credit for the indexing behavior. I took what numarray had done and extended it just a little bit to allow mixing of slices and index arrays. It was easily one of the most complicated things to write for NumPy. What you are observing is called "partial indexing" by Numarray. The indexing rules where also spelled out in emails to this list last year and placed in the design document for what was then called Numeric3 (I'm not sure if that design document is still visible or not (probably under old.scipy.org it could be found). The section in my book that covers this is based on that information. I can't pretend to have use cases for all the indexing fanciness because I was building off the work that numarray had already pioneered. -Travis |