我正在尝试编译这种代码:
def my_func(double c, int m):
cdef double f[m][m]
f = [[c for x in range(m)] for y in range(m)]
...
这引发了:
Error compiling Cython file:
------------------------------------------------------------
def grow(double alpha, double beta, double gamma, int m, int s):
cdef double f[m][m]
^
------------------------------------------------------------
test.pyx:6:22: Not allowed in a constant expression
之后我假设我不能在指定的地方使用变量,我尝试使用数值:
def my_func(double c, int m):
cdef double f[500][500]
f = [[c for x in range(500)] for y in range(500)]
...
但后来我得到:
Error compiling Cython file:
------------------------------------------------------------
f = [[beta for x in range(500)] for y in range(500)]
^
------------------------------------------------------------
test.pyx:13:6: Assignment to non-lvalue 'f'
所以,我想知道如何在 cython 代码中声明和制作 2D 列表。我在谷歌搜索“cython 2D list”的文档中找不到这种示例