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 = np.ctypeslib.as_array(x) >
That's a pretty simple approach. There is a faster approach which uses the undocumented function int_asbuffer function from numpy.core.multiarray (i.e. from numpy.core.multiarray import int_asbuffer) Then: x = np.frombuffer(int_asbuffer(C.addressof(x.contents), n*8)) If you don't like the hard-coded '8', then you can get that number from np.dtype(float).itemsize There may also be a way to get it from ctypes. -Travis _______________________________________________ Numpy-discussion mailing list [email protected] http://projects.scipy.org/mailman/listinfo/numpy-discussion
