3
我正在使用Scipy優化模塊,具體爲fmin_tnc和fmin_l_bfgs_b。但是,使用其中一個時,我收到消息「IndexError:標量變量無效的索引」。Python/Scipy「無效索引到標量變量」
這個錯誤的原因是什麼?
這個錯誤信息的含義是什麼?
我的做法代碼:
def f01(para):
para1, para2 = para
return 1+ (para1 -1)**2 + (para2 -2)**2
para0 = np.array([10, 10])
mybounds = [(-40,30),(-20,15)]
opt.fmin_l_bfgs_b(f01, para0, bounds = mybounds)
將返回:
Traceback (most recent call last):
File "C:\Python27\mystuff\practice_optimize01.py", line 78, in <module>
opt.fmin_l_bfgs_b(f01, para0, bounds = mybounds)
File "C:\Python27\lib\site-packages\scipy\optimize\lbfgsb.py", line 174, in fm
in_l_bfgs_b
**opts)
File "C:\Python27\lib\site-packages\scipy\optimize\lbfgsb.py", line 294, in _m
inimize_lbfgsb
f, g = func_and_grad(x)
File "C:\Python27\lib\site-packages\scipy\optimize\lbfgsb.py", line 249, in fu
nc_and_grad
f = fun(x, *args)
File "C:\Python27\lib\site-packages\scipy\optimize\optimize.py", line 55, in _
_call__
self.jac = fg[1]
IndexError: invalid index to scalar variable.
的Python 2.7.3,32位。 Numpy 1.6.2。 Scipy 0.11.0b1。 Windows XP和Vista。
工作很好。非常感謝! – beets 2012-08-15 22:23:53
布拉沃!非常感謝,我非常困惑。 – 2014-06-03 02:35:20