How to pass a numpy array of string types to a function in Cython

后端 未结 2 799
天命终不由人
天命终不由人 2021-02-05 08:46

Passing a numpy array of dtype np.float64_t works fine ( below), but I can\'t pass string arrays.

This is what works :

# c         


        
2条回答
  •  走了就别回头了
    2021-02-05 09:31

    With Cython 0.20.1 it works using cdef np.ndarray, without specifying the data type and the number of dimensions:

    import numpy as np
    cimport numpy as np
    
    cdef func1(np.ndarray A):
        print A
    
    def testing():
        chunk = np.array([['huh','yea'], ['swell','ray']])
        func1(chunk)
    

提交回复
热议问题