0

As part of a larger project, I end up with convex expressions like ((x_0 + x_1)^2 + x_2^2:

from cvxpy import Variable, sum_squares, sum

target = Variable(3, nonneg=True, name='Target')
sum(target)
sum_squares(target)

combo = [sum([target[0], target[1]]), target[2]]
sum(combo)
sum_squares(combo)

sum(combo) works fine, but sum_squares(combo) throws the following error

ValueError: setting an array element with a sequence.

despite both atoms being scalar functions of with array inputs. Is there a better way to rewrite this?

rene
  • 41,474
  • 78
  • 114
  • 152
rhaskett
  • 1,864
  • 3
  • 29
  • 48

1 Answers1

3

sum_squares does not take array input. The input needs to be a single CVXPY Expression. Use vstack, hstack, or bmat to combine multiple Expressions into a single vector or matrix Expression.

steven
  • 671
  • 4
  • 8