加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – 带有指针数组的cython

发布时间:2020-12-16 21:55:38 所属栏目:Python 来源:网络整理
导读:我在python中有一个numpy.ndarrays(具有不同长度)的列表,需要能够非常快速地访问python中的那些.我认为一系列指针可以解决这个问题.我试过了: float_type_t* list_of_arrays[no_of_arrays]for data_array in python_list_of_arrays: list_of_arrays[0] = da

我在python中有一个numpy.ndarrays(具有不同长度)的列表,需要能够非常快速地访问python中的那些.我认为一系列指针可以解决这个问题.我试过了:

float_type_t* list_of_arrays[no_of_arrays]
for data_array in python_list_of_arrays:
    list_of_arrays[0] = data_array

但是cython抱怨:

no_of_arrays < Not allowed in a constant expression

我已经尝试了几种方法来满足这个变量:

cdef extern from *:
    ctypedef int const_int "const int"

(有更多的创造性尝试) – 但不幸的是它不起作用.

请帮忙.

最佳答案
为什么不使用numpy对象数组而不是数组列表?

我认为你遇到的问题是因为你在堆栈中声明了list_of_arrays,并且它的大小必须在编译时知道.你可以尝试一些dynamic allocation,像这样:

from libc.stdlib cimport malloc,free

cdef float_type_t *list_of_arrays = 
    

(这假设data_array是一个numpy数组.)

但这仍然是猜测你想要做什么.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读