[SciPy-User] [ANN] la 0.2, the labeled array

Keith Goodman kwgoodman at gmail.com
Thu Apr 29 12:51:27 EDT 2010


On Thu, Apr 29, 2010 at 12:37 AM, Sebastian Haase <seb.haase at gmail.com> wrote:
> how would you say do larrys compare to numpy recarrays ? Can you
> convert one to the other ? - IOW why do put the labels in a separate
> list instead of the dtype ?

(Lately I've been getting mail from the numpy and scipy lists all at
once, once a day or so. Anyone else seeing the same?)

I'm not familiar with recarrays. But I think recarrays rely on
position to determine the dtype. So the first element of a record will
always have the same dtype (well, unless you change it).

With larrys the position of the data doesn't matter. Only the label
matters. In binary operations, for example, two larrys will be aligned
by labels:

>> from la import larry
>> x = [[1, 2], [3, 4]]
>> label = [['north', 'south'], ['west', 'east']]
>> lar1 = larry(x,  label)
>>
>> x = [[1, 2], [3, 4]]
>> label = [['south', 'north'], ['west', 'east']]  # flip north <--> south
>> lar2 = larry(x,  label)
>>
>> lar1 + lar2

label_0
    north
    south
label_1
    west
    east
x
array([[4, 6],
       [4, 6]])

Also all data in any one larry has the same dtype since the data is
stored in a numpy array.

Now for the real answer (I think):

recarrays:

>> x = np.array([(1.0, 2), (3.0, 4)], dtype=[('x', float), ('y', int)])
>> x.sum()
<...>
TypeError: cannot perform reduce with flexible type

larry:

>> x = lar1 + lar2
>> x.sum()
   20



More information about the SciPy-User mailing list