I have a C library that I am wrapping in Python using ctypes . The C library contains many arrays (tens of thousands of arrays of the order of 5-100 elements each, plus several much longer arrays) that I want to get as numpy arrays in Python. I thought it would be just using numpy.ctypeslib.as_array ; however, when I look at my code using cProfile , I notice that it is much faster to use the Python loop to copy (!) the data from the ctypes to numpy pointers that I create on the Python side. ctypeslib.as_array be slow? - I would think that it would be much faster to just interpret some memory as a numpy array than copy it over the elements inside the Python loop.
source share