擅长:python、mysql、java
<p>为什么不直接使用numpy数组呢?实际上,它并不是静态的(参见末尾的注释),但您可以在全局范围内分配它,以便在模块启动时创建它。您还可以访问下面的原始C数组,这样就没有真正的效率成本。在</p>
<pre><code>import numpy as np
# at module global scope
cdef double[::1] rk_coeffs = np.zeros((50,)) # avoid having to manually fill with 0s
# illustratively fill the non-zero elements
rk_coeffs[1] = 2.0
rk_coeffs[3] = 5.0
# if you need to convert to a C array
cdef double* rk_coeffs_ptr = &rk_coeffs[0]
</code></pre>
<p><em>注意</em>我对这个问题的理解是,您使用“static”来表示“compiled into the module”,而不是任何<a href="https://stackoverflow.com/questions/572547/what-does-static-mean-in-a-c-program">numerous C-related definitions</a>或任何与Python静态方法/类变量有关的内容。在</p>