我的环境是运行SciPy 1.3.1和NumPy 1.17.2的Python 3.74。
我正在尝试使用scipy.optimize.minimize函数来查找约束非线性多变量函数的最小值,该函数已构建为cost()
。
尝试运行以下代码摘录时,我遇到了TypeError
:
constraints = [
{'type' : 'ineq', 'fun' : AA},
{'type' : 'ineq', 'fun' : Ev},
{'type' : 'eq', 'fun' : Aeq},
{'type' : 'eq', 'fun' : Beq}
]
bnds = ((-5, 5))
z = minimize(lambda z: cost(z,to), x0=z0, constraints=constraints, method='SLSQP')
AA是(96,48),值从-0.5到0 Ev是(96,1),值3和5 Aeq为(5,1),全为-0.5 Beq为0
我假设有一个问题,如documentation所述,这些都不是“可调用的”。如果是这种情况,我该怎么做?
回溯如下:
Exception has occurred: TypeError
'numpy.ndarray' object is not callable
File "C:\Users\Jack\AppData\Roaming\Python\Python37\site-packages\scipy\optimize\slsqp.py", line 313, in <listcomp>
for c in cons['eq']]))
File "C:\Users\Jack\AppData\Roaming\Python\Python37\site-packages\scipy\optimize\slsqp.py", line 313, in _minimize_slsqp
for c in cons['eq']]))
File "C:\Users\Jack\AppData\Roaming\Python\Python37\site-packages\scipy\optimize\_minimize.py", line 608, in minimize
constraints, callback=callback, **options)
File "F:\[redactedpath]\main.py", line 125, in <module>
z = minimize(lambda z: cost(z,to), x0=z0, constraints=constraints, method='SLSQP')
File "C:\Users\Jack\AppData\Local\Programs\Python\Python37-32\Lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Jack\AppData\Local\Programs\Python\Python37-32\Lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\Jack\AppData\Local\Programs\Python\Python37-32\Lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
由于机密性,我无法提供完整代码,但是如果您需要更多信息,请提出建议,我会回复。 谢谢。