Closed stroxler closed 11 years ago
It might be confusing to allow axis=None for 1d but not for nd > 1. Another option is to flatten the larry.
Create a 2d larry:
I[4] lar = la.lrange(label=[['row1', 'row2'], ['col1', 'col2']])
I[5] lar
O[5]
label_0
row1
row2
label_1
col1
col2
x
array([[0, 1],
[2, 3]])
Now flatten the larry and cumsum:
I[6] lar.flatten().cumsum(axis=0)
O[6]
label_0
('row1', 'col1')
('row1', 'col2')
('row2', 'col1')
('row2', 'col2')
x
array([0, 1, 3, 6])
or flattening in "F" order instead of "C":
I[8] lar.flatten(order='F').cumsum(axis=0)
O[8]
label_0
('row1', 'col1')
('row2', 'col1')
('row1', 'col2')
('row2', 'col2')
x
array([0, 2, 3, 6])
But that is confusing too.
I don't see an obvious solution, so closing this feature request.
Numpy has an axis=None default for cumsum. I'm not sure whether that would be a good idea for larry in general, because numpy flattens out the array when axis is None. But it might be handy to at least allow it for 1d larrys and raise an error if there is no axis and the larry is multi-dimensional. That would make the interfaces a bit more compatible.