Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Meet larry, the labeled numpy array

tree: 79b5a5c64e

Fetching latest commit…

Cannot retrieve the latest commit at this time


Who's larry?

The main class of the la package is a labeled array, larry. A larry consists of data and labels. The data is stored as a NumPy array and the labels as a list of lists (one list per dimension).

Here's larry in schematic form:

             date1    date2    date3
    'AAPL'   209.19   207.87   210.11
y = 'IBM'    129.03   130.39   130.55
    'DELL'    14.82    15.11    14.94

The larry above is stored internally as a Numpy array and a list of lists:

y.label = [['AAPL', 'IBM', 'DELL'], [date1, date2, date3]]
y.x = np.array([[209.19, 207.87, 210.11],
                [129.03, 130.39, 130.55],
                [ 14.82,  15.11,  14.94]])

A larry can have any number of dimensions except zero. Here, for example, is one way to create a one-dimensional larry:

>>> import la
>>> y = la.larry([1, 2, 3])

In the statement above the list is converted to a Numpy array and the labels default to range(n), where n in this case is 3.

larry has built-in methods such as ranking, merge, shuffle, move_sum, zscore, demean, lag as well as typical Numpy methods like sum, max, std, sign, clip. NaNs are treated as missing data.

Alignment by label is automatic when you add (or subtract, multiply, divide) two larrys. You can also specify the join method (inner, outer, left, right) for binary operations on two larrys with unaligned labels.

You can archive larrys in HDF5 format using save and load or using a dictionary-like interface:

>>> io = la.IO('/tmp/dataset.hdf5')
>>> io['y'] = y   # <--- save
>>> z = io['y']   # <--- load
>>> del io['y']   # <--- delete from archive

For the most part larry acts like a Numpy array. And, whenever you want, you have direct access to the Numpy array that holds your data. For example if you have a function, myfunc, that works on Numpy arrays and doesn't change the shape or ordering of the array, then you can use it on a larry, y, like this:

y.x = myfunc(y.x)

larry adds the convenience of labels, provides many built-in methods, and let's you use your existing array functions.


The la package is distributed under a Simplified BSD license. Parts of NumPy, Scipy, and numpydoc, which all have BSD licenses, are included in la. Parts of matplotlib are also included. See the LICENSE file, which is distributed with the la package, for details.



la Python 2.7, 3.2 NumPy 1.6.2, 1.7.0 Bottleneck 0.7.0
Unit tests nose


Archive larrys in HDF5 h5py, HDF 1.8
Compile for speed boost gcc or MinGW
lar.ranking(norm='gaussian') SciPy

You can download the latest version of la and Bottleneck from the Python Package Index.

GNU/Linux, Mac OS X et al.

To install la:

$ python build
$ sudo python install

Or, if you wish to specify where la is installed, for example inside /usr/local:

$ python build
$ sudo python install --prefix=/usr/local

Alternatively, you can use the makefile to install la inplace:

$ make all


In order to (optionally) compile the C code in the la package you need a Windows version of the gcc compiler. MinGW (Minimalist GNU for Windows) contains gcc and has been used to successfully compile la on Windows.

Install MinGW and add it to your system path. Then install la with the commands:

python build --compiler=mingw32
python install

Post install

After you have installed la, run the suite of unit tests:

>>> import la
>>> la.test()
Ran 3012 tests in 9.225s
<nose.result.TextTestResult run=3012 errors=0 failures=0>

The la package contains C extensions that speed up common alignment operations such as adding two unaligned larrys. If the C extensions don't compile when you build la then there's an automatic fallback to python versions of the functions. To see whether you are using the C functions or the Python functions:

la version      0.7.0
la file         /usr/local/lib/python2.6/dist-packages/la/__init__.pyc
NumPy           1.6.2
Bottleneck      0.6.0
HDF5 archiving  Available (h5py 2.0.0)
listmap         Faster C version
listmap_fill    Faster C version

Since la can run in a pure python mode, you can use la by just saving it and making sure that python can find it.


mailing list
issue tracker
Something went wrong with that request. Please try again.