如何创建任意大小的cython结构数组

时间:2019-03-21 19:09:47

标签: cython

我想知道如何在Cython中创建一个结构数组,然后可以填充并进行计算。

示例

这里有Cython代码

%%cython 
cimport numpy as cnp
cimport cython


from collections import namedtuple

Couple = namedtuple('Couple', ['female', 'male'], verbose=False)

cdef struct CyCouple:
    int female
    int male


cpdef int np_cy_count_women_earning_more2(list py_couples):

    cdef:
        int count = 0, r, N
        CyCouple cy_couples[100_0000] # THIS IS HARDCODED

    N  = len(py_couples)

    make_CyCouple_array(py_couples, cy_couples, N)

    for n in range(N):
        r = cy_couples[n].female > cy_couples[n].male
        count += r
    return count

我想要一个通用版本,而不是#THIS IS HARDCODED中的定义。

我该怎么办?

0 个答案:

没有答案
相关问题