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
       
numpy.core.numerictypes
os
numpy.core.numeric
sys
types

 
Functions
       
array(obj, dtype=None, shape=None, offset=0, strides=None, formats=None, names=None, titles=None, aligned=False, byteorder=None, copy=True)
Construct a record array from a wide-variety of objects.
find_duplicate(list)
Find duplication in a list, return a list of duplicated elements
fromarrays(arrayList, dtype=None, shape=None, formats=None, names=None, titles=None, aligned=False, byteorder=None)
create a record array from a (flat) list of arrays
 
>>> x1=np.array([1,2,3,4])
>>> x2=np.array(['a','dd','xyz','12'])
>>> x3=np.array([1.1,2,3,4])
>>> r = np.core.records.fromarrays([x1,x2,x3],names='a,b,c')
>>> print r[1]
(2, 'dd', 2.0)
>>> x1[1]=34
>>> r.a
array([1, 2, 3, 4])
fromfile(fd, dtype=None, shape=None, offset=0, formats=None, names=None, titles=None, aligned=False, byteorder=None)
Create an array from binary file data
 
If file is a string then that file is opened, else it is assumed
to be a file object.
 
>>> from tempfile import TemporaryFile
>>> a = np.empty(10,dtype='f8,i4,a5')
>>> a[5] = (0.5,10,'abcde')
>>>
>>> fd=TemporaryFile()
>>> a = a.newbyteorder('<')
>>> a.tofile(fd)
>>>
>>> fd.seek(0)
>>> r=np.core.records.fromfile(fd, formats='f8,i4,a5', shape=10,
... byteorder='<')
>>> print r[5]
(0.5, 10, 'abcde')
>>> r.shape
(10,)
fromrecords(recList, dtype=None, shape=None, formats=None, names=None, titles=None, aligned=False, byteorder=None)
create a recarray from a list of records in text form
 
    The data in the same field can be heterogeneous, they will be promoted
    to the highest data type.  This method is intended for creating
    smaller record arrays.  If used to create large array without formats
    defined
 
    r=fromrecords([(2,3.,'abc')]*100000)
 
    it can be slow.
 
    If formats is None, then this will auto-detect formats. Use list of
    tuples rather than list of lists for faster processing.
 
>>> r=np.core.records.fromrecords([(456,'dbe',1.2),(2,'de',1.3)],
... names='col1,col2,col3')
>>> print r[0]
(456, 'dbe', 1.2)
>>> r.col1
array([456,   2])
>>> r.col2
chararray(['dbe', 'de'],
      dtype='|S3')
>>> import cPickle
>>> print cPickle.loads(cPickle.dumps(r))
[(456, 'dbe', 1.2) (2, 'de', 1.3)]
fromstring(datastring, dtype=None, shape=None, offset=0, formats=None, names=None, titles=None, aligned=False, byteorder=None)
create a (read-only) record array from binary data contained in
a string
get_remaining_size(fd)

 
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'>, ...}