[Numpy-discussion] recarray fun
Stéfan van der Walt
stefan at sun.ac.za
Wed Apr 30 15:20:55 EDT 2008
Hi Chris
2008/4/30 Christopher Barker <Chris.Barker at 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
http://www.scipy.org/RecordArrays
> 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).
Cheers
Stéfan
More information about the NumPy-Discussion
mailing list