bundles / numpy 2.4.4 / numpy / ctypeslib / as_array
function
numpy.ctypeslib:as_array
Signature
def as_array ( obj , shape = None ) Summary
Create a numpy array from a ctypes array or POINTER.
Extended Summary
The numpy array shares the memory with the ctypes object.
The shape parameter must be given if converting from a ctypes POINTER. The shape parameter is ignored if converting from a ctypes array
Examples
Converting a ctypes integer array:import ctypes ctypes_array = (ctypes.c_int * 5)(0, 1, 2, 3, 4) np_array = np.ctypeslib.as_array(ctypes_array) np_arrayConverting a ctypes POINTER:
import ctypes buffer = (ctypes.c_int * 5)(0, 1, 2, 3, 4) pointer = ctypes.cast(buffer, ctypes.POINTER(ctypes.c_int)) np_array = np.ctypeslib.as_array(pointer, (5,)) np_array
Aliases
-
numpy.ctypeslib.as_array