Two new functions: isaligned and sortby

5 views
Skip to first unread message

Keith Goodman

unread,
Jul 22, 2011, 10:17:24 AM7/22/11
to labele...@googlegroups.com
There are two new functions in the development version of la (which
will become la 0.6):

- la.isaligned() returns True if two larrys are aligned along specified axis
- la.sortby() sorts 2d larry by the row or column corresponding to
given label element

isaligned example:

Make two 2d larrys that are aligned along columns but not rows:

>>> lar1 = larry([[1, 2], [3, 4]], [['row1', 'row2'], ['col1', 'col2']])
>>> lar2 = larry([[1, 2], [3, 4]], [['row2', 'row1'], ['col1', 'col2']])

The two larrys are not aligned:

>>> la.isaligned(lar1, lar2)
False
>>> la.isaligned(lar1, lar2, axis=0)
False

But the columns of the two larrys are aligned:

>>> la.isaligned(lar1, lar2, axis=1)
True

sortby example:

Create a larry:

>>> label = [['a','b'], ['c','d','e']]
>>> x = np.array([[1, 2, 3], [3, 1, 2]])
>>> lar = la.larry(x, label)

Sort larry by row 'b' along the first axis:

>>> la.sortby(lar, 'b', axis=0)
label_0
a
b
label_1
d
e
c
x
array([[2, 3, 1],
[1, 2, 3]])

Nick Crawford

unread,
Jul 27, 2011, 6:56:27 PM7/27/11
to labeled-array
Sweet! Thanks for including this!

Keith Goodman

unread,
Jul 27, 2011, 7:03:21 PM7/27/11
to labele...@googlegroups.com
On Wed, Jul 27, 2011 at 3:56 PM, Nick Crawford <ngcra...@gmail.com> wrote:
> Sweet!  Thanks for including this!

Thanks for suggesting the sortby function.

Reply all
Reply to author
Forward
0 new messages