【发布时间】:2021-08-09 16:03:06
【问题描述】:
假设我有这段代码:
def test(params, *args):
return params[0] + params[1]
minVal = minimize(test, [0.01, 0.02]) # I want minVal to be lowest non-negative value
有了这样的约束,我可以将结果限制在 0 以上:
# forces test(params) >= 0
con = [{"type" : "ineq", "fun" : test}]
minVal = minimize(test, x0=[0.01, 0.02], constraints=con)
但是如果我希望值大于 4 怎么办?可以指定吗?
【问题讨论】:
标签: python scipy minimization