← Back to team overview

larry-discuss team mailing list archive

Re: Index by label support added to experimental branch

 

On Mon, Feb 8, 2010 at 3:37 PM, Keith Goodman <kwgoodman@xxxxxxxxx> wrote:
> On Mon, Feb 8, 2010 at 12:27 PM, Keith Goodman <kwgoodman@xxxxxxxxx> wrote:
>> I made a branch called index-by-label:
>>
>> https://code.launchpad.net/~kwgoodman/larry/index-by-label
>>
>> and added support for indexing by label. It is all self contained in
>> one method: deflarry.py(lix). So easy to try.
>>
>> Here are a few one-off tests:
>>
>>>> y = la.larry([[1,2],[3,4]], [['a', 'b'], ['c', 'd']])
>>
>>>> y.lix[['a']]
>> label_0
>>    c
>>    d
>> x
>> array([1, 2])
>>
>>>> y.lix[['b', 'a']]
>> label_0
>>    b
>>    a
>> label_1
>>    c
>>    d
>> x
>> array([[3, 4],
>>       [1, 2]])
>>
>>>> y.lix[['a']:]
>> label_0
>>    a
>>    b
>> label_1
>>    c
>>    d
>> x
>> array([[1, 2],
>>       [3, 4]])
>>
>>>> y.lix[:['b']]
>> label_0
>>    a
>> label_1
>>    c
>>    d
>> x
>> array([[1, 2]])
>>
>>>> y.lix[['a'], ['c']:]
>> label_0
>>    c
>>    d
>> x
>> array([1, 2])
>>
>>>> y.lix[['a'], ['d', 'c']]
>> label_0
>>    d
>>    c
>> x
>> array([2, 1])
>>
>>>> y.lix['a':]  # <--- expected to crash
>> ValueError: The start element of a slice must be a list.
>
> I think the only thing left to add is the conversion of fancy indexing
> to rectangular:
>
>>> y.lix[['a', 'b'], ['d', 'c']]
> IndexError: tuple index out of range
>
> How do I identify rectangular indexing? If more than one list with
> more than one element are present anywhere in the index, then it is
> rectangular and I need to do your trick np.array(first list)[:,None]?

that's the idea, with matching axes added

can you use np.idx_ directly, once you have the numeric index list ?

y.x[np.ix_(lists of indices)]

might not work with slices, to avoid problems with mixing slices and
array indexing, I converted slices in the past to a array of indices

slice(None)   -> np.arange(x.shape(ax))

then np.ix_ or broadcasting can take over

Josef


>
> _______________________________________________
> Mailing list: https://launchpad.net/~larry-discuss
> Post to     : larry-discuss@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~larry-discuss
> More help   : https://help.launchpad.net/ListHelp
>



Follow ups

References