[Numpy-discussion] first recarray steps

Vincent Schut schut@sarvision...
Tue May 20 09:34:16 CDT 2008


Hi, I'm trying to get into recarrays. Unfortunately documentation is a 
bit on the short side...

Lets say I have a rgb image of arbitrary size, as a normal ndarray 
(that's what my image reading lib gives me). Thus shape is 
(3,ysize,xsize), dtype = int8. How would I convert/view this as a 
recarray of shape (ysize, xsize) with the first dimension split up into 
'r', 'g', 'b' fields? No need for 'x' and 'y' fields.

I tried creating a numpy dtype {names: ('r','g','b'), formats: 
(numpy.int8,)*3}, but when I try to raw_img.view(rgb_dtype) I get:
"ValueError: new type not compatible with array."

Now this probably should not be too difficult, but I just don't see it...

Thanks,
Vincent.



More information about the Numpy-discussion mailing list