Module nestedrecords :: Class NestedRecArray
[show private | hide private]
[frames | no frames]

Type NestedRecArray

object --+            
         |            
  _ndarray --+        
             |        
       NDArray --+    
                 |    
          RecArray --+
                     |
                    NestedRecArray


Array of nested records.

This is a generalization of the numarray.records.RecArray class. It supports nested fields and records via the NestedRecord class.

This class is compatible with RecArray. However, part of its behaviour has been extended to support nested fields:

  1. Getting a single item from an array will return a NestedRecord, a special kind of Record with support for nested structures.
  2. Getting a range of items will return another NestedRecArray instead of an ordinary RecArray.
  3. Getting a whole field may return a NestedRecArray instead of a NumArray or CharArray, if the field is nested.

Fields and sub-fields can be accessed using both the field() method and the fields interface, which allows accessing fields as Python attributes: nrec = nrarr.fields.f1.fields.subf1[4]. The field() method supports the '/' separator to access sub-fields.

Nested record arrays can be converted to ordinary record arrays by using the asRecArray() method.

Finally, the constructor of this class is not intended to be used directly by users. Instead, use one of the creation functions (array(), fromarrays() or the others).


Method Summary
  __init__(self, recarray, descr)
  asRecArray(self)
Convert a nested array to a non-nested equivalent array.
  field(self, fieldName)
Get field data as an array.
    Inherited from RecArray
  __add__(self, other)
Add two RecArray objects in a row wise manner
  __getstate__(self)
returns pickled state dictionary for RecArray
  __repr__(self)
  __setstate__(self, state)
restores state of NDArray after unpickling.
  __str__(self)
  byteswap(self)
Byteswap data in place and change the _byteorder attribute.
  getbyteorder(self)
  info(self)
info() prints out key attributes of a record array.
  reshape(*value)
  togglebyteorder(self)
reverses the state of the _byteorder attribute: little <-> big.
  view(self)
    Inherited from NDArray
  __copy__(self)
support for copy.copy()
  __deepcopy__(self, memo)
support for copy.deepcopy()
  __nonzero__(self)
  __reduce__(self)
__reduce__ returns the pickling "reduction tuple" for an NDArray.
  astype(self, type)
  copy(self)
Return a new array with the same shape and type, but a copy of the data
  factory(self, *args, **keys)
factory(...) calls the array(...) factory function defined in the source module where the class of 'self' was defined.
  getflat(self)
  getrank(self)
  getshape(self)
  is_c_array(self)
is_c_array() returns 1 iff the array is aligned and contiguous, and returns 0 otherwise.
  itemsize(self)
Size (in bytes) of an array element
  nonzero(self)
  put(self, *indices, **keywords)
  ravel(self)
ravel(self) setshapes 'self' into an equivalent 1D array.
  repeat(self, repeats, axis)
repeat() returns a new array with each element 'a[i]' repeated 'r[i]' times.
  resize(self, shape, *args)
resize() shrinks/grows 'self' to new 'shape', possibly replacing the underlying buffer object.
  setflat(self, flat)
  setshape(self, shape, *args)
Change array shape in place.
  take(self, *indices, **keywords)
  tofile(self, file)
Write the array as a binary image to a file.
  tostring(self)
Return a string with a binary copy of the array
  transpose(self, axes)
transpose() re-shapes the array by permuting it's dimensions as specified by 'axes'.
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __reduce_ex__(...)
helper for pickle
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value

Property Summary
    Inherited from NDArray
  flat: access to array as 1D
  shape: tuple of array dimensions

Method Details

asRecArray(self)

Convert a nested array to a non-nested equivalent array.

This function creates a new vanilla RecArray instance equivalent to this one by flattening its fields. Only bottom-level fields are included in the array. Sub-fields are named by prepending the names of their parent fields up to the top-level fields, using '/' as a separator.

The data area of the array is copied into the new one.

Example

Let us take the following nested array:

>>> nra = array([(1, (0, 0), ('a1', 1j)), (2, (0, 0), ('a2', 2j))],
...             names=['id', 'pos', ('info', ['name', 'value'])],
...             formats=['Int64', '(2,)Float32', ['a2', 'Complex64']])

Calling nra.asRecArray() would return the same array as calling:

>>> ra = numarray.records.array(
...     [(1, (0, 0), 'a1', 1j), (2, (0, 0), 'a2', 2j)],
...     names=['id', 'pos', 'info/name', 'info/value'],
...     formats=['Int64', '(2,)Float32', 'a2', 'Complex64'])

Please note that the shape of multi-dimensional fields is kept.

field(self, fieldName)

Get field data as an array.

If the named field (fieldName, a string) is not nested, a NumArray or CharArray object representing the values in that field is returned. Else, a NestedRecArray object is returned.

fieldName can be used to provide the name of sub-fields. In that case, it will consist of several field name components separated by the string '/'. For instance, if there is a nested field named x with a sub-field named y, the last one can be accesed by using 'x/y' as the value of fieldName.

Overrides:
numarray.records.RecArray.field

Generated by Epydoc 2.1 on Thu Apr 21 13:11:50 2005 http://epydoc.sf.net