[Numpy-discussion] recarray fun

Stéfan van der Walt stefan@sun.ac...
Wed Apr 30 14:20:55 CDT 2008

Hi Chris

2008/4/30 Christopher Barker <Chris.Barker@noaa.gov>:
>  Someone on the wxPython list posted a nifty recarray example that I
>  don't quite understand. The idea is to have an array for an RGBA image:
>  rgbarec = numpy.dtype({'r':(numpy.uint8,0),
>                         'g':(numpy.uint8,1),
>                         'b':(numpy.uint8,2),
>                         'a':(numpy.uint8,3)})

I find manipulating data with records arrays highly intuitive; I had
the same approach in mind when I wrote


>  One more idea -- is there a way to have two arrays, each with a
>  different dtype, that point to the same data? maybe:
>  RGBImage = numpy.zeros(shape, dtype=rgbarec )
>  IntImage = RGBImage.view()
>  IntImage.dtype = numpy.uint32
>  That way you could work with it either way, whichever was easier in the
>  context.

That's the way, or just rgba_image.view(numpy.int32).


More information about the Numpy-discussion mailing list