[Numpy-discussion] Indexing arrays with arrays

Bill Baxter wbaxter at gmail.com
Thu May 18 07:57:09 EDT 2006


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?

Thanks
--bb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20060518/8336ed53/attachment.html>


More information about the NumPy-Discussion mailing list