構造体の配列

2022/09/11

cython [test.pyx]

cdef struct Data:
    float x
    float y

cdef class Test:
    cdef Data d[10]

    def __cinit__(self):
        cdef int i
        for i in range(10):
            self.d[i].x = i
            self.d[i].y = i+1

    def get(self):
        ls = []
        cdef int i
        for i in range(10):
            ls.append(self.d[i].x)
            ls.append(self.d[i].y)
        return ls

python

import test
print(test.Test().get())