我正在使用ctypes将numpy ndarray
传递给C函数:
lib = np.ctypeslib.load_library('library', 'path/to/library.so')
lib.function.argtypes = [ numpy.ctypeslib.ndpointer(ndim=1, dtype=numpy.float64, flags='C,A,W') ]
lib.function.restype = None
arr = numpy.zeros((10), dtype=numpy.float64)
lib.function(arr)
具有以下C函数:
void function(double *arr)
{
arr = (double *) realloc(arr, 20 * sizeof(double));
}
但是,数组保持原始大小。使用numpy.ctypeslib.ndpointer
时是否有一种简单的方法允许numpy数组更改大小?