How to convert python array to cython array?

后端 未结 5 845
失恋的感觉
失恋的感觉 2020-12-17 22:14

I have an array of float values that is created in regular Python, that I want to pass to a cython function that fronts for an underlying C function. The C function requires

5条回答
  •  鱼传尺愫
    2020-12-17 22:51

    This is what I use for preparing arrays for passing to Cython, or C/CPP with SWIG.

    import numpy as np    
    def make_c_array(a):
        """
        Take an input numpy array and convert to being ready for use in C.
        """
        b = []
        for i in range(len(a)):
            b.append(a[i])
        a = np.array(b,dtype=np.dtype('d'),order='C')
        return a
    

提交回复
热议问题