当我在约束中使用预定义的np数组时,CVXPY给出“ AttributeError:'numpy.bool_'对象没有属性'variables'”错误

时间:2019-10-05 23:10:14

标签: python cvxpy

我正在尝试在预定义的np阵列上找到最佳解决方案,并且需要在约束中使用这些阵列。我尝试将这些数组转换为cvxpy变量,但它说cvxpy变量不支持赋值。这是参考代码。有人可以提供一些提示吗?

N,d = xTr.shape     y = yTr.flatten()

## Solution Start

# dummy code: example of establishing objective and constraints, and let the solver solve it.
si = np.random.randn(N)
w = Variable(d)
b = Variable(1)
objective = norm(w) + C * (sum(si))
constraints = []
for i in range(N):
    constraints += [
                    y[i]*(w * xTr[i] + b)+ si[i] >=1,
                    si[i] >= 0
                  ]
prob = Problem(Minimize(objective), constraints)
prob.solve()>

0 个答案:

没有答案