Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Meet larry, the labeled numpy array
Python C Shell
Tag: v0.1.0

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.



    Larry is a labeled Numpy array. Here's a 2d larry, y, in schematic form:
                                   date1    date2    date3
                          'AAPL'   123.45   127.23   132.60
                     y =  'IBM'    234.56   234.56   234.56
                          'DELL'   456.67   460.07   458.23
    Larry stores the data as a Numpy array and the labels as a list of lists
    (one list for each dimension):
        y.label = [['AAPL', 'IBM', 'DELL'], [date1, date2, date3]]
        y.x = np.array([[123.45, 127.23, 132.60],
                        [234.56, 234.56, 234.56],
                        [456.67, 460.07, 458.23]])               
    A larry can have any dimension. Here, for example, is one way to create a
    1d larry:

    >>> import la
    >>> y = la.larry([1, 2, 3])
    The list is converted to a Numpy array and the labels default to range(n),
    where n in this case is 3.
    Larry has many builtin methods such as movingsum, ranking, merge, shuffle,
    zscore, demean, lag as well as typical Numpy methods like sum, max, std,
    sign, clip. NaNs are treated as missing data.
    Alignment is automatic when you add (or subtract, multiply, divide) two
    You can archive larrys in HDF5 format 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 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 builtin functions, and
    let's you use your exisiting array functions.       


    The la package requires Python and Numpy. Numpy 1.4 or newer is
    recommended for its improved NaN handling. Also some of the unit tests in
    the la package require Numpy 1.4 or newer.

    To save and load larrys in HDF5 format, you need h5py with HDF5 1.8.
    The la package currently contains no extensions, just Python code, so
    there is nothing to compile. You can just save the la package and make
    sure Python can find it.
    Atlernatively, you can install the traditional way:

        $ python build
        $ sudo python install
    Or, if you wish to specify where la is installed, for example inside
        $ python build
        $ sudo python install --prefix=/usr/local
    After you have installed la, run the suite of unit tests:
        >>> import la
        >>> la.test()

Something went wrong with that request. Please try again.