CVXPY:处理嵌套总和时 sum_squares 中可能存在错误?

CVXPY: possible bug in sum_squares when handling nested sums?

作为一个更大项目的一部分,我最终得到了像 ((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) 工作正常,但 sum_squares(combo) 抛出以下错误

ValueError: setting an array element with a sequence.

尽管两个原子都是数组输入的标量函数。有没有更好的方法来重写这个?

sum_squares 不接受数组输入。输入需要是单个 CVXPY Expression。使用 vstackhstackbmat 将多个 Expressions 组合成一个向量或矩阵 Expression.