numpy.core.records | index /usr/lib/python2.6/dist-packages/numpy/core/records.py |
Record Arrays
=============
Record arrays expose the fields of structured arrays as properties.
Most commonly, ndarrays contain elements of a single type, e.g. floats, integers,
bools etc. However, it is possible for elements to be combinations of these,
such as::
>>> a = np.array([(1, 2.0), (1, 2.0)], dtype=[('x', int), ('y', float)])
>>> a
array([(1, 2.0), (1, 2.0)],
dtype=[('x', '<i4'), ('y', '<f8')])
Here, each element consists of two fields: x (and int), and y (a float).
This is known as a structured array. The different fields are analogous
to columns in a spread-sheet. The different fields can be accessed as
one would a dictionary::
>>> a['x']
array([1, 1])
>>> a['y']
array([ 2., 2.])
Record arrays allow us to access fields as properties::
>>> ar = a.view(np.recarray)
>>> ar.x
array([1, 1])
>>> ar.y
array([ 2., 2.])
Modules | ||||||
|
Functions | ||
|
Data | ||
__all__ = ['record', 'recarray', 'format_parser'] __file__ = '/usr/lib/python2.6/dist-packages/numpy/core/records.pyc' __name__ = 'numpy.core.records' __package__ = 'numpy.core' _byteorderconv = {'<': '<', '=': '=', '>': '>', 'B': '>', 'I': '|', 'L': '<', 'N': '=', 'S': 's', 'b': '>', 'i': '|', ...} _typestr = {<type 'numpy.int64'>: 'i8', <type 'numpy.int16'...py.complex128'>: 'c16', <type 'numpy.void'>: 'V'} numfmt = {0: <type 'numpy.bool_'>, 1: <type 'numpy.int8'>, 2: <type 'numpy.uint8'>, 3: <type 'numpy.int16'>, 4: <type 'numpy.uint16'>, 5: <type 'numpy.int32'>, 6: <type 'numpy.uint32'>, 7: <type 'numpy.int64'>, 8: <type 'numpy.uint64'>, 9: <type 'numpy.int64'>, ...} |