我正在尝试在预定义的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()>