PyTables User's Guide: Hierarchical datasets in Python - Release 1.3.3
Prev | Chapter 4. Library Reference | Next

# 4.11. The CArray class

This is a child of the `Array` class (see 4.10) and as such, `CArray` represents an array on the file. The difference is that `CArray` has a chunked layout and, as a consequence, it also supports compression. You can use this class to easily save or load array (or array slices) objects to or from disk, with compression support included.

## 4.11.1. CArray instance variables

In addition to the attributes that `CArray` inherits from `Array`, it supports some more that provide information about the filters used.

atom

  An `Atom` (see 4.16.3) instance representing the shape, type and flavor of the atomic objects to be saved.

## 4.11.2. Example of use

See below a small example of `CArray` class. The code is available in `examples/carray1.py`.

    import numarray
    import tables

    fileName = 'carray1.h5'
    shape = (200,300)
    atom = tables.UInt8Atom(shape = (128,128))
    filters = tables.Filters(complevel=5, complib='zlib')

    h5f = tables.openFile(fileName,'w')
    ca = h5f.createCArray(h5f.root, 'carray', shape, atom, filters=filters)
    # Fill a hyperslab in ca. The array will be converted to UInt8 elements
    ca[10:60,20:70] = numarray.ones((50,50))
    h5f.close()

    # Re-open a read another hyperslab
    h5f = tables.openFile(fileName)
    print h5f
    print h5f.root.carray[8:12, 18:22]
    h5f.close()

The output for the previous script is something like:

    carray1.h5 (File) ''
    Last modif.: 'Thu Jun 16 10:47:18 2005'
    Object Tree:
    / (RootGroup) ''
    /carray (CArray(200L, 300L)) ''

    [[0 0 0 0]
     [0 0 0 0]
     [0 0 1 1]
     [0 0 1 1]]

Prev | Home | Next
The Array class | Up | The EArray class