【发布时间】:2019-11-09 22:31:56
【问题描述】:
我正在寻找一种方法来重写下面的代码,以便 numba 可以使用它。目前,运行代码会提供错误Use of unsupported NumPy function 'numpy.meshgrid' or unsupported use of the function.。本质上,我正在计算 3 元 catesian 积(例如 [0...13] x [0..13] x [0..13])。
@numba.jit(nopython=True)
def sequences_of_length(repeat, n_values):
a = list(range(0, n_values))
c = [a] * repeat
x = np.array(np.meshgrid(*c), dtype=np.int16).T.reshape(-1, repeat)
return x
例如sequences_of_length(3, 13)应该输出:
[[ 0 0 0]
[ 0 1 0]
[ 0 2 0]
...
[12 10 12]
[12 11 12]
[12 12 12]]
(2197, 3)
(其中 2197 = 13^3)
【问题讨论】:
标签: python numba cartesian-product