How to write several constraint in cvxpy?
问题 I want to add many constraint in a optimization problem under cvxpy. In matlab I can do so by adding a line subject to and then use for loop to generate the constraints. How can I do the same work in cvxpy, as there is no 'subject to' concepts in cvxpy. any suggestion please? 回答1: In Python constraints is a list. You can use for loop to append/extend it like this (and CVXPY functions make it easier). import cvxpy as cvx samples = 10 x = cvx.Variable(samples) y = range(1, samples+1)