calling c from python with ctypes: passing vectors

前端 未结 3 1947
忘了有多久
忘了有多久 2021-01-13 14:22

I want to call a c function from python using ctypes. From the documentation I don\'t understand how to pass pointer to vectors. The function I want to call is:



        
3条回答
  •  天涯浪人
    2021-01-13 15:01

    apparently I needed to specify the flag contigous to make it work

    http://scipy-lectures.github.io/advanced/interfacing_with_c/interfacing_with_c.html

    this is an extract from my code:

    array_1d_double = numpy.ctypeslib.ndpointer(dtype=numpy.double, ndim=1, 
                                                flags='CONTIGUOUS')
    libc.f.argtypes = [c_int, array_1d_double]
    libc.f(n, x)
    

提交回复
热议问题