我正在尝试使用scipy中的linprog来解决线性编程问题。但是我收到导入错误。
这是错误
AttributeError: 'module' object has no attribute 'linprog'
代码如下。
import numpy as np
from scipy import optimize as opt
bounds = []
for i in xrange(6):
bounds.append((0, 1))
bounds = tuple(bounds)
W = np.zeros((3, 6))
W[1, 2] = 0.4
W[2, 3] = 0.5
b = np.transpose(np.zeros(3))
b[1] = 0.8
b[2] = 0.25
res = opt.linprog(c, A_eq=W, b_eq=b, bounds=bounds, options={"disp": True})
我使用的是Python 2.7.10和Scipy 0.13.0b1
你的scipy版本已经过时了(从2013年开始,我猜)。
docs的linprog部分说:
版本0.15.0中的新功能。
而你的是Scipy 0.13.0b1。
所以外卖的消息是:你的版本不支持这个优化器。
(使用最近的scipy,这个错误消失了,虽然代码仍然被破坏:没有c定义)