x = np.frombuffer(int_asbuffer(C.addressof(x.contents), n*8))
I'll go with your faster solution. Very good. Thank you very much.
Paulo
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
Hello,
I am writing some code interfacing C and Python using ctypes. In a
callback function (in Python) I get in a parameter x which is c_double
pointer and a parameter n which is c_int representing the length of the
array.
How can I transform this information into a numpy array?
Paulo
Paulo J. S. Silva wrote:
Hello,
I am writing some code interfacing C and Python using ctypes. In a
callback function (in Python) I get in a parameter x which is c_double
pointer and a parameter n which is c_int representing the length of the
array.
How can I transform this information
Em Qui, 2008-09-04 às 15:01 -0500, Travis E. Oliphant escreveu:
Paulo J. S. Silva wrote:
Something like this may work:
from numpy import ctypeslib
r = ctypeslib.as_array(x._type_ * n)
Unfortunately, it didn't work.
If that doesn't work, then you can create an array from an
After some trial and erros, I found a solution, described below. Is this
the best one? Looks a little convoluted to me (C represents ctypes
module and np numpy):
Array = n*C.c_double
x = Array.from_address(C.addressof(x.contents))
x = np.ctypeslib.as_array(x)
Thanks,
Paulo J. S. Silva wrote:
After some trial and erros, I found a solution, described below. Is this
the best one? Looks a little convoluted to me (C represents ctypes
module and np numpy):
Array = n*C.c_double
x = Array.from_address(C.addressof(x.contents))
x =