如何将numpy.view与numba中的字符串数据一起使用



我无法使用numba将以下代码进行jit。有其他方法吗?我希望结果是一个字符串数组。代码在没有numba jit的情况下完全按照预期运行。

from numba import jit
import numpy as np
@jit(nopython=True)
def test():
chars = np.array([[97, 98, 99, 0, 0],[99, 98, 97, 0, 0]], dtype=np.uint8)
return chars.view(dtype='<S5').astype(str).squeeze()
test()

我在numba gitter频道上询问过这件事,被告知不支持。我决定接受以下内容。在真正的函数中有额外的处理,这是可以忽略的,拉出最后一小部分可以在所有其他部分上进行加速,效果非常好。

from numba import jit
import numpy as np
@jit(nopython=True)
def test():
chars = np.array([[97, 98, 99, 0, 0],[99, 98, 97, 0, 0]], dtype=np.uint8)
dtypes5 = np.dtype('<S5')
return chars.view(dtypes5)
test().astype(str).squeeze()

最新更新