Take the 2-minute tour ×  I have allocated a chunk of double in
a C library and I would like to create a numpy 1D array based on
that data; ideally I would like two versions one which only
wraps the c_ptr readonly - letting the C layer retain ownership
of the data, and one which copies the data. So simplified code
would be like this:   double * init_and_alloc( size_t size ) {
double * ptr = malloc( size * sizeof * ptr );   // initialize
ptr     return ptr;    Python code  size = 1000  c_ptr =
ctypes_func_ptr_init_and_alloc( size )   numpy_array =
numpy.xxxx( c_ptr , size , dtype.float64) <--- ?????  So does
the function I have labelled xxxx exist?  Best Regards  Joakim
Hove  share|improve this question add comment  1 Answer  Yes,
numpy.ctypeslib.as_array To get a given dtype, as_array(ptr,
shape).view(dtype).  This should work, at least in theory (don't
have time to test it now).  share|improve this answer add
comment  Your Answer