[Numpy-discussion] display numpy array as image
Thu Nov 29 17:33:12 CST 2007
Zachary Pincus wrote:
> Hello all,
> I'm curious if people have experience with / preferences for how to
> display a numpy array onscreen as an image.
> Pyglet looks relatively easy -- you can feed an image buffer object
> with a string or a ctypes pointer. I presume getting a string from an
> array is plenty fast, but the ctypes pointer option is intriguing as
> it allows for dealing with simple strided arrays (the image objects
> allow for an arbitrary number of bytes between rows). Is it possible
> to get a ctypes pointer to the beginning of the array buffer from
> numpy without too much ugliness?
In : from numpy import *
In : a = arange(10)
In : dir(a.ctypes)
In : import ctypes
In : a.ctypes.data_as(ctypes.POINTER(ctypes.c_long))
Out: <ctypes.LP_c_long object at 0x1b353a0>
In : a.ctypes.get_shape()
Out: <numpy.core._internal.c_long_Array_1 object at 0x1c096c0>
In : a.ctypes.get_strides()
Out: <numpy.core._internal.c_long_Array_1 object at 0x1c09710>
In : a.ctypes.get_as_parameter()
You might want to use the new ctypes-based OpenGL 3.0+ package. It has numpy
support a bit more directly. You can use Pyglet for its windowing and all of the
other surrounding infrastructure and use OpenGL directly for the drawing.
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Numpy-discussion