简体   繁体   中英

CVXPY: possible bug in sum_squares when handling nested sums?

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM