我正在使用numba的jit代码加速,代码如下:
@jit(nopython=True)
def testrun2():
for i in range(5):
nx = np.empty(shape=(0,1))
for j in range(5):
nx=np.append(nx,[eta2[j]*(hour_avgV2[j]/hour_avgV1[i])])
print(nx.mean())
if __name__ == '__main__':
t1 = time.time()
testrun2()
t2 = time.time()
print(t2-t1)
报错如下:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Cannot unify array(float64, 2d, C) and array(float64, 1d, C) for 'nx.2', defined at /tmp/ipykernel_8059/3388145730.py (5)
File "../../../../tmp/ipykernel_8059/3388145730.py", line 5:
<source missing, REPL/exec in use?>
During: typing of assignment at /tmp/ipykernel_8059/3388145730.py (5)
File "../../../../tmp/ipykernel_8059/3388145730.py", line 5:
<source missing, REPL/exec in use?>
如果我把@jit(nopython=True)注销掉,这代码可以正常运行。或者如果我把nx = np.empty(shape=(0,1))这一行放入第二层for循环,代码也可以正常运行,但是这不符合我的运算逻辑。
请问有什么方法能够解决这个问题吗?
你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答
本次提问扣除的有问必答次数,已经为您补发到账户,我们后续会持续优化,扩大我们的服务范围,为您带来更好地服务。