所以我试图使用优化的最小化来最小化给定参数的数组函数,它给了我这个错误:
回溯(最后一次调用):文件“plot2.py”,第 72 行,在 res = minimum(rosen(al,c), c, args=(al)) 文件“/home/usd/.local/lib/ python3.6/site-packages/scipy/optimize/_minimize.py”,第 604 行,在最小化返回 _minimize_bfgs(fun, x0, args, jac, callback, **options) 文件“/home/usd/.local/lib /python3.6/site-packages/scipy/optimize/optimize.py”,第 1003 行,在 _minimize_bfgs old_fval = f(x0) 文件“/home/usd/.local/lib/python3.6/site-packages/scipy /optimize/optimize.py", line 327, in function_wrapper return function(*(wrapper_args + args)) TypeError: 'numpy.float64' object is not callable
这是代码:
def rosen(xi,c):
return sum((xi[1:] - xi[:-1]-c)*(xi[1:] - xi[:-1]-c))
for index, k in enumerate(jo):
for ko in range(len(alp2[index])):
al = alp[index]
al2 = alp[index+1]
al = np.array(al)
be = alp2[index][ko]
be2 = alp2[index][ko]
c = 5
print(rosen(al,c))
res = minimize(rosen(al,c), c, args=(al))