I am using a Python (via ctypes
) wrapped C library to run a series of computation. At different stages of the running, I want to get data into Python, and spec
Another possibility (which may require more recent versions of libraries than is available when the first answer was written -- I tested something similar with ctypes 1.1.0
and numpy 1.5.0b2
) is to convert from the pointer to the array.
np.ctypeslib.as_array(
(ctypes.c_double * array_length).from_address(ctypes.addressof(y.contents)))
This seems to still have the shared ownership semantics, so you probably need to make sure that you free the underlying buffer eventually.