答案 0 :(得分:1)
只需使用索引选择一个子集(在下面的示例中:经典的基于python的切片;但可以使用更复杂的索引/ numpy样式):
示例:
from cvxpy import *
x = Variable(5)
constraints = []
constraints.append(x >= 0) # all vars
constraints.append(x <= 10) # all vars
constraints.append(sum_entries(x[:3]) <= 3) # only part of vector; sum(first-three) <=3
objective = Maximize(sum_entries(x))
problem = Problem(objective, constraints)
problem.solve()
print(problem.status)
print(x.value.T)
输出:
optimal
[[ 1. 1. 1. 10. 10.]]
我也怀疑你在这里误解了这个问题,但那个公式图像当然不完整。