Scipy 未导入线性规划

Scipy not importing linear programming

我正在尝试使用 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 部分说:

New in version 0.15.0.

而你的是 Scipy 0.13.0b1.

所以要点是:你的版本不支持这个优化器。

(使用最近的 scipy,此错误已消失,但代码仍然损坏:未定义 c)