[Numpy-discussion] numpy/Windows shared arrays between processes?
Tue Oct 9 16:50:05 CDT 2007
Ray S wrote:
> Yes, a different methodology attempt. It would be interesting to know
> anyway how to create a numpy array from an address; it's probably
> buried in the undocumented C-API that I don't grok, and likely
> frowned upon.
Make a dummy object that exposes the __array_interface__ attribute filled with
the appropriate information:
Something like the following should suffice (untested, though I've done similar
things with ctypes before):
def fromaddress(address, dtype, shape, strides=None):
""" Create a numpy array from an integer address, a dtype, a shape
tuple, and possibly strides.
# Make sure our dtype is a dtype, not just "f" or whatever.
dtype = numpy.dtype(dtype)
d = Dummy()
d.__array_interface__ = dict(
data = (address, False),
typestr = dtype.str,
descr = dtype.descr,
shape = shape,
strides = strides,
version = 3,
"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