[Numpy-discussion] storage for records

Stefan van der Walt stefan at sun.ac.za
Thu Feb 16 13:55:05 CST 2006


On Thu, Feb 16, 2006 at 02:06:15PM -0700, Travis Oliphant wrote:
> Stefan van der Walt wrote:
> 
> >Is there any way to control the underlying storage for a record?
> >
> >I am trying to use Travis' earlier example of an image with named fields:
> >
> >dt = N.dtype('<f12', [('r','<f4'),('g','<f4'),('b','<f4')])
> >img = N.array(N.empty((rows,columns)), dtype=dt)
> >
> >Using this, I can access the different bands of the image using
> >
> >img['r'], img['g'], img['b'] (but not img.r as mentioned in some of
> >the posts).
> > 
> >
> Attribute lookup (img.r) is the purpose of the record array subclass.
> 
> rimg= img.view(numpy.recarray)
> 
> rimg.r --- will now work.

Thanks for the quick response!  This is very useful information.

Regards
Stéfan




More information about the Numpy-discussion mailing list