【发布时间】:2015-03-19 16:30:11
【问题描述】:
我是使用 Python 和 scipy 进行优化的新手。我收到了错误
IndexError: SLSQP Error: the length of bounds is not compatible with that of x0.
尝试将bounds 参数传递给scipy.optimize.minimize 时
x0 = np.array([[2,2,2,2,2,2,2,2,2,2,2],[2,2,2,2,2,2,2,2,2,2,2]])
bounds = ( [(0,12000),(0,12000),(0,12000),(0,12000),(0,12000),(0,12000),(0,12000),(0,12000),(0,12000),(0,12000),(0,12000)], [(0,12000),(0,12000),(0,12000),(0,12000),(0,12000),(0,12000),(0,12000),(0,12000),(0,12000),(0,12000),(0,12000)] )
x_max = optimize.minimize(f, x0.flatten(), method='SLSQP', bounds=bounds)
对于这样的x0,应该如何定义bounds?
【问题讨论】:
标签: python python-2.7 numpy scipy