A ctypes pointer to the middle of a numpy array

I know how to get the ctypes pointer to the beginning of a numpy array:

a = np.arange(10000, dtype=np.double) p = a.ctypes.data_as(POINTER(c_double)) p.contents c_double(0.0) 

however, I need to pass a pointer, for example, to element 100, without copying the array. There should be an easy way to do this, but he cannot find it.

Any hint is appreciated.

+7
source share
1 answer

Slicing a numpy array creates a view, not a copy:

 >>> a = numpy.arange(10000, dtype=numpy.double) >>> p = a[100:].ctypes.data_as(ctypes.POINTER(ctypes.c_double)) >>> p.contents c_double(100.0) >>> a[100] = 55 >>> p.contents c_double(55.0) 
+11
source

All Articles