I have a numpy array with a custom dtype:
a = np.zeros(100, dtype=np.dtype([('one',np.double),('two',np.int)]))
a['one']=np.arange(100)
a['two']=np.arange(100)*-1
I want to create a ctypes pointer that I can pass to a C library.
The problem is that the C library expects just a pointer to a double array, the ‘one’ field.
I tried with:
a[‘one’].ctypes.data_as(ctypes.POINTER(ctypes.c_double))
but it does not work, I believe because the C routine does not know what is the correct stride to go trough the array.
Would you have any suggestion, possibly without copying the array?
You are going to have to copy the data to a contiguous array.