我正在尝试编写一个初始化数组并在返回之前将其改组的函数。
    将numba导入为nb

@nb.jit(nopython=True, cache=True)
def test(x):
    ind = np.array(range(len(x)))
    np.random.shuffle(ind)
    return ind


错误消息说我使用了不支持的功能或数据类型:

NotImplementedError: range_state_int64 cannot be represented as a Numpy dtype


numba是否支持numpy.random.shuffle()?如何修改?谢谢!

最佳答案

实际上,这与random.shuffle无关,因为numba supports the random module out of the box

这里的问题是设置range标志时numba cannot support the nopython object(因为它是python对象)。用range代替np.arange

@nb.njit(cache=True)  # same as @nb.jit(nopython=True, ...)
def test(x):
    ind = np.arange(len(x))
    np.random.shuffle(ind)
    return ind

test([1, 2, 3])
# array([1, 0, 2])

关于python - NotImplementedError:range_state_int64不能表示为Numpy dtype,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56498210/

10-13 00:08