我有一个list_of_arrays3D numpy数组列表,我想用模板传递给C函数
int my_func_c(double **data, int **shape, int n_arrays)
Run Code Online (Sandbox Code Playgroud)
这样的
data[i] : pointer to the numpy array values in list_of_arrays[i]
shape[i] : pointer to the shape of the array in list_of_arrays[i] e.g. [2,3,4]
Run Code Online (Sandbox Code Playgroud)
如何my_func_c使用cython接口函数调用?
我的第一个想法是做类似下面的事情(有效),但我觉得有一个更好的方法就是使用numpy数组而不需要mallocing和freeing.
# my_func_c.pyx
import numpy as np
cimport numpy as np
cimport cython
from libc.stdlib cimport malloc, free
cdef extern from "my_func.c":
double my_func_c(double **data, int **shape, int n_arrays)
def my_func(list list_of_arrays):
cdef int n_arrays = len(list_of_arrays)
cdef double **data = <double …Run Code Online (Sandbox Code Playgroud)