我的代码有两个 2D numpy 数组,z
和weights
. 我正在像这样迭代它们(同时转置它们):
import statsmodels.api as sm
import numpy as np
for y1, w in zip(z.T, weights.T): # building the parameters per j class
temp_g = sm.WLS(y1, iself.X, w).fit()
这很好,直到我开始使用 Numba 来加速我的代码。使用 Numba,我收到此错误:
numba.error.NumbaError: (see below)
--------------------- Numba Encountered Errors or Warnings ---------------------
for y1, w in zip(z.T, weights.T): # building the parameters per j class
------------^
Error 82:12: Only a single target iteration variable is supported at the moment
--------------------------------------------------------------------------------
为了解决这个问题,我想我可以简单地这样做:
for y1 in z.T:
for w in weights.T:
temp_g = sm.WLS(y1, iself.X, w).fit()
但是我还不太擅长python,所以我只想知道这是否是最好的方法?或者如果有另一种更优化的方式?