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

后端 未结 2 798
天命终不由人
天命终不由人 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:29

    Looks like you're out of luck.

    http://cython.readthedocs.org/en/latest/src/tutorial/numpy.html

    Some data types are not yet supported, like boolean arrays and string arrays.


    This answer is no longer valid as shown by Saullo Castro's answer, but I'll leave it for historical purposes.

    0 讨论(0)
  • 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)
    
    0 讨论(0)
提交回复
热议问题