gpt4 book ai didi

python - 如何在 CVXPY 中取变量列表的 2-范数?

转载 作者:行者123 更新时间:2023-11-30 22:50:28 27 4
gpt4 key购买 nike

我想取变量列表的 2-范数。如何将序列转换为 CVXPY 兼容的变量“列表”?有办法处理这个问题吗?提前致谢。例如,

    test_a=cvxpy.Variable(1)
test_b=cvxpy.Variable(1)
mylist= [test_a,test_b]
mynorm=cvxpy.norm(mylist,2) #error thrown for this line


packages/cvxpy/interface/matrix_utilities.py", line 63, in size
return (len(constant[0]), len(constant))

最佳答案

CVXPY 函数无法应用于列表。您需要使用vstack,即

mynorm=cvxpy.norm(cvxpy.vstack(*mylist),2)

关于python - 如何在 CVXPY 中取变量列表的 2-范数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39331642/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com