【发布时间】:2019-10-25 06:00:01
【问题描述】:
我正在运行一个@nb.njit 函数,我试图在其中将一个整数放入一个字符串数组中。
import numpy as np
import numba as nb
@nb.njit(nogil=True)
def func():
my_array = np.empty(6, dtype=np.dtype("U20"))
my_array[0] = np.str(2.35646)
return my_array
if __name__ == '__main__':
a = func()
print(a)
我收到以下错误:
numba.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<class 'str'>) with argument(s) of type(s): (float64)
我应该使用哪个函数在numba 内进行从float 到string 的转换?
【问题讨论】:
-
你可能想在github.com/numba/numba/issues提出这个问题
-
当您只是将浮点数转换为要插入的字符串时,您是否有理由使用字符串数组?我很好奇为什么不只使用 float64 dtype 的数组。
-
我在现实世界的用例中有其他元素(日期),将它们全部作为字符串处理更简单。我最终确实把它们都当作花车处理了。
标签: python string numpy floating-point numba