[Numpy-discussion] nested recarrays
oliphant at ee.byu.edu
Sun Dec 24 19:22:05 CST 2006
Matthew Koichi Grimes wrote:
> (Newbie alert.)
> I'm having trouble making a nested record array. I'm trying to work from
> the following example on the scipy.org examples page:
> >>> mydescriptor = dtype([('x', 'f4'),('y', 'f4'), # nested recarray
> ... ('nested', [('i', 'i2'),('j','i2')])])
> >>> myarr = array([(1.0, 2.0, (1,2))], dtype=mydescriptor)
> ... but this isn't really a nested recarray, since you can't refer to
> fields 'x', 'y', or 'nested' as attributes:
It is nested but, yes, it's not as convenient as attribute access.
> When I try modifying the above example by simply replacing the 'array'
> constructor with 'recarray', I get the following error, which I haven't
> really grokked yet:
The problem is that recarray is not analagous with array. It is
analagous with ndarray.
Use N.rec.array instead.
More information about the Numpy-discussion