[Numpy-discussion] Advanced indexing: "fancy" vs. orthogonal

Jaime Fernández del Río jaime.frio at gmail.com
Sun Apr 5 03:45:13 EDT 2015


On Fri, Apr 3, 2015 at 10:59 AM, Jaime Fernández del Río <
jaime.frio at gmail.com> wrote:

> I have an all-Pyhton implementation of an OrthogonalIndexer class, loosely
> based on Stephan's code plus some axis remapping, that provides all the
> needed functionality for getting and setting with orthogonal indices.
>
> Would those interested rather see it as a gist to play around with, or as
> a PR adding an orthogonally indexable `.ix_` argument to ndarray?
>

A PR it is, #5749 <https://github.com/numpy/numpy/pull/5749> to be precise.
I think it has all the bells and whistles: integers, boolean and integer
1-D arrays, slices, ellipsis, and even newaxis, both for getting and
setting. No tests yet, so correctness of the implementation is dubious at
best. As a small example:

>>> a = np.arange(60).reshape(3, 4, 5)
>>> a.ix_
<numpy.core._indexer.OrthogonalIndexer at 0x1027979d0>
>>> a.ix_[[0, 1], :, [True, False, True, False, True]]
array([[[ 0,  2,  4],
        [ 5,  7,  9],
        [10, 12, 14],
        [15, 17, 19]],

       [[20, 22, 24],
        [25, 27, 29],
        [30, 32, 34],
        [35, 37, 39]]])
>>> a.ix_[[0, 1], :, [True, False, True, False, True]] = 0
>>> a
array([[[ 0,  1,  0,  3,  0],
        [ 0,  6,  0,  8,  0],
        [ 0, 11,  0, 13,  0],
        [ 0, 16,  0, 18,  0]],

       [[ 0, 21,  0, 23,  0],
        [ 0, 26,  0, 28,  0],
        [ 0, 31,  0, 33,  0],
        [ 0, 36,  0, 38,  0]],

       [[40, 41, 42, 43, 44],
        [45, 46, 47, 48, 49],
        [50, 51, 52, 53, 54],
        [55, 56, 57, 58, 59]]])

Jaime

-- 
(\__/)
( O.o)
( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus planes
de dominación mundial.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150405/1ab6a7b5/attachment.html>


More information about the NumPy-Discussion mailing list