Re: [Numpy-discussion] Getting a numpy array from a ctype pointer

2008-09-05 Thread Paulo J. S. Silva
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

[Numpy-discussion] Getting a numpy array from a ctype pointer

2008-09-04 Thread Paulo J. S. Silva
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

Re: [Numpy-discussion] Getting a numpy array from a ctype pointer

2008-09-04 Thread Travis E. Oliphant
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

Re: [Numpy-discussion] Getting a numpy array from a ctype pointer

2008-09-04 Thread Paulo J. S. Silva
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

Re: [Numpy-discussion] Getting a numpy array from a ctype pointer

2008-09-04 Thread Paulo J. S. Silva
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,

Re: [Numpy-discussion] Getting a numpy array from a ctype pointer

2008-09-04 Thread Travis E. Oliphant
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 =