我正在使用 Scipy 优化模块,特别是 fmin_tnc 和 fmin_l_bfgs_b。但是,在使用其中任何一个时,我都会收到消息“IndexError:标量变量的索引无效”。
这个错误的原因是什么?
这个错误信息的含义是什么?
我的练习代码:
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 位。麻木 1.6.2。Scipy 0.11.0b1。Windows XP 和 Vista。