I tried to solve a convex problem with cvxpy as below.
import cvxpy as cp
import numpy as np
# Problem data.
Q = np.array([[13, 12, -2], [12, 17, 6], [-2, 6, 12]])
q = np.array([[-22, -14.5, 13]])
r = 1
# Construct the problem.
x = cp.Variable((3,1))
objective = cp.Minimize(np.dot(np.dot(x.T, Q), x) + np.dot(q, x) + r)
constraints = [0 <= x[0:], x[0:] <= 1]
prob = cp.Problem(objective, constraints)
# The optimal objective value is returned by `prob.solve()`.
result = prob.solve()
# The optimal value for x is stored in `x.value`.
print(x.value)
# The optimal Lagrange multiplier for a constraint is stored in
# `constraint.dual_value`.
print(constraints[0].dual_value)
However, I get this error:
ValueError: setting an array element with a sequence.
I don't know why this error occurs because everything else seems to work.
Edit: Please let me know if the problem statement is needed.
cp.Variable(3,1)should not do.np.dotshould not be there. Reason 1: cvxpy does not know what to do with it (it's external stuff) Reason 2: np.dot() is a less algebraic expression, while cvxpy allows allows algebraic expr likeA*x(mat-vec mul), for example, where numpy would need dot. Reason 3: You want cvxpy'squad_formexpression i suppose.