scipy.optimize.minimize()示例中的标准函数错误?

时间:2013-10-30 15:20:11

标签: python scipy

我将很快解释发生了什么。我正在学习(scipy.optimize tutorial)示例(Nelder-Mead Simplex algorithm)以了解最小化函数,但错误发生如下所示。 我该如何解决?我没有添加任何新值,我只是复制了示例值和示例。

from scipy import optimize

def rosen(x):
     return sum(100.0*(x[1:]-x[:-1]**2.0) + (1 - x[:-1])**2.0)

x0 = np.array([1.3, 0.7, 0.8, 1.9, 1.2])
res = optimize.minimize(rosen, x0, method='nelder-mead',
            options={'xtol': 1e-8, 'disp': True})


Command line: C:\Python27\python.exe C:\Users\Desktop\FSFDSD~1.PY
Working directory: C:\Users\Desktop
Timeout: 0 ms

Traceback (most recent call last):
  File "C:\Users\Desktop\FSFDSD~1.PY", line 49, in <module>
    main()
  File "C:\Users\Desktop\FSFDSD~1.PY", line 40, in main
    options={'xtol': 1e-8, 'disp': True})
  File "C:\Python27\lib\site-packages\scipy\optimize\_minimize.py", line 338, in minimize
    return _minimize_neldermead(fun, x0, args, callback, **options)
  File "C:\Python27\lib\site-packages\scipy\optimize\optimize.py", line 424, in 
 _minimize_neldermead
    fsim[0] = func(x0)
  File "C:\Python27\lib\site-packages\scipy\optimize\optimize.py", line 268, in function_wrapper
    return function(x, args)
TypeError: rosen() takes exactly 1 argument (2 given)

Process "Python Interpreter" terminated, ExitCode: 00000001

0 个答案:

没有答案