[Numpy-discussion] storage for records

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


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).

'img' itself is a matrix of similar dimension as img['r'], but
contains the combined items of type '<f12'.

However, I would like to store the image as a 3xMxN array, with the r,
g and b bands being contained in

img[0], img[1] and img[2]

Is there a way to construct the record so that this structure is used
for storage?  Further, how do I specify the dtype above, i.e.

N.dtype('<f12', [('r','<f4'),('g','<f4'),('b','<f4')])

in the style

N.dtype({'names' : ['r','g','b'], 'formats': ['f4','f4','f4']})

(how do I specify that the combined type is 'f12')?

I tried to find some documentation on record arrays, but couldn't find
anything.  Any pointers appreciated!

Cheers
Stéfan




More information about the Numpy-discussion mailing list