Yes, use cvxpy.bmat to construct A as a block matrix.

A_00 = cvxpy.Variable(1)
A = cvxpy.bmat([[A_00, ... rest of row 1],
                [row 2],
                ...,
                [last row]])

More info: https://www.cvxpy.org/tutorial/functions/index.html#vector-matrix-functions

Answer from thomaskeefe on Stack Overflow
🌐
Cvxpy
cvxpy.org › tutorial › functions › index.html
Atomic Functions -
Historically, CVXPY used expr1 * expr2 to denote matrix multiplication. This is now deprecated. Starting with Python 3.5, users can write expr1 @ expr2 for matrix multiplication and dot products.
🌐
Cvxpy
cvxpy.org › tutorial › intro › index.html
What is CVXPY? -
# A scalar variable. a = cp.Variable() # Vector variable with shape (5,). x = cp.Variable(5) # Column vector variable with shape (5, 1). x = cp.Variable((5, 1)) # Matrix variable with shape (4, 7). A = cp.Variable((4, 7)) You can use your numeric library of choice to construct matrix and vector constants. For instance, if x is a CVXPY Variable in the expression A @ x + b, A and b could be Numpy ndarrays, SciPy sparse matrices, etc.
🌐
Stack Overflow
stackoverflow.com › questions › 70257737 › create-matrix-from-vector-cvxpy-variable
python - Create matrix from vector cvxpy variable - Stack Overflow
I know that in MatLAB, I can declare an expression holder, like "expression A(5,5)", then assign each element in A, then use "A==semidefinite(5)" when declaring the constraint. How should I do it in python with cvxpy? ... and then enforce the zeros and the relevant places. It's equal to define a vector first (as you did) and then build a matrix from that.
🌐
Cvxpy
cvxpy.org › api_reference › cvxpy.expressions.html
Expressions -
Gives the (sub/super)gradient of the expression w.r.t. each variable. Matrix expressions are vectorized, so the gradient is a matrix.
🌐
GitHub
github.com › cvxpy › cvxpy › issues › 198
N-dimensional variables · Issue #198 · cvxpy/cvxpy
April 23, 2015 - Currently cvxpy only supports scalar, vector, and matrix variables. Additional dimensions can be mimicked using a dict: # Create a 3D k-by-m-by-n variable. x = {} for i in range(k): x[i] = Variable(m,n)
Author   SteveDiamond
🌐
GitHub
github.com › cvxpy › cvxpy › discussions › 2039
Most efficient way to construct and use sparse matrix as variables? · cvxpy/cvxpy · Discussion #2039
Writing the matrices explicitly in terms of isolated scalar variables is the only thing that worked, and I also had to write the objective function manually, otherwise I get the same "lazy evaluation/not implemented" error then. The result of this is that ultimately, even if everything is written in terms of sparse matrices and matrix multiplication and reshapings, the actual objects being manipulated are very large in CVXPY's representation, and mostly made of trivial sums of sparse matrices with single 1s at specific positions, just to "assemble" the sparse structure by hand.
Author   cvxpy
🌐
Cvxpy
cvxpy.org › _modules › cvxpy › expressions › variable.html
Source code for cvxpy.expressions.variable
[docs] def name(self) -> str: """The name of the variable.""" return self._name def is_constant(self) -> bool: return False @property def grad(self) -> Optional[dict[Variable, sp.csc_array]]: """Gives the (sub/super)gradient of the expression w.r.t. each variable. Matrix expressions are vectorized, so the gradient is a matrix.
🌐
Blogger
yetanothermathprogrammingconsultant.blogspot.com › 2019 › 11 › cvxpy-matrix-style-modeling-limits.html
Yet Another Math Programming Consultant: CVXPY matrix style modeling limits
November 7, 2019 - For this model, the CVXPY representation is very compact but depending on the formulation it requires more than casual familiarity with matrix notation. Arguably, the most important feature of a modeling tool is readability. I have a preference to the GAMS notation here: it is closer to the original mathematical model in a notation I am used to. When printing the results, GAMS is a bit more intuitive: GAMS: ---- 66 VARIABLE x.L shipment quantities in cases new-york chicago topeka seattle 50.000 300.000 san-diego 275.000 275.000 Python: [[ 3.17321312e+01 3.00004719e+02 2.71849569e-03] [ 2.93267895e+02 -2.77023874e-03 2.74995427e+02]]
Find elsewhere
🌐
Cvxpy
cvxpy.org › version › 1.2 › api_reference › cvxpy.expressions.html
Expressions — CVXPY 1.2 documentation
Gives the (sub/super)gradient of the expression w.r.t. each variable. Matrix expressions are vectorized, so the gradient is a matrix.
🌐
Cvxpy
cvxpy.org › tutorial › advanced › index.html
Advanced Features -
optimal (x + y == 1) dual variable 6.47610300459e-18 optimal (x - y >= 1) dual variable 2.00025244976 x - y value: 0.999999986374
🌐
Google Groups
groups.google.com › g › cvxpy › c › 5MgCLMsJHuk
higher dimensional variables / variable indexing in cvxpy
You can create a map of tuple to matrix variable. Like this: ... For 4D arrays the keys would be tuples with two elements, etc. Would you mind telling me more about how you're using the ND arrays? I may add ND arrays to cvxpy at some point, but I want to understand the use cases better first.
🌐
Cvxpy
cvxpy.org › tutorial › constraints › index.html
Advanced Constraints -
# Creates a 10-vector constrained to have boolean valued entries. x = cp.Variable(10, boolean=True) # expr1 must be boolean valued. constr1 = (expr1 == x) # Creates a 5 by 7 matrix constrained to have integer valued entries. Z = cp.Variable((5, 7), integer=True) # expr2 must be integer valued. constr2 = (expr2 == Z) CVXPY provides interfaces to many mixed-integer solvers, including open source and commercial solvers.
🌐
Cvxpy
cvxpy.org › examples › basic › sdp.html
Semidefinite program -
X = cp.Variable((n,n), symmetric=True) # The operator >> denotes matrix inequality. constraints = [X >> 0] constraints += [ cp.trace(A[i] @ X) == b[i] for i in range(p) ] prob = cp.Problem(cp.Minimize(cp.trace(C @ X)), constraints) prob.solve() # Print result.
🌐
Readthedocs
ajfriendcvxpy.readthedocs.io › en › latest › tutorial › intro
What is CVXPY? — CVXPY 0.2.25 documentation
CVXPY provides the following constants as aliases for the different status strings: ... Variables can be scalars, vectors, or matrices. # A scalar variable. a = Variable() # Column vector variable of length 5. x = Variable(5) # Matrix variable with 4 rows and 7 columns.
🌐
Cvxopt
cvxopt.org › userguide › modeling.html
Modeling — CVXOPT User's Guide
The function value. If any of the variables of f has value None, then f.value() returns None. Otherwise, it returns a dense 'd' matrix of size (len(f),1) with the function value computed from the value attributes of the variables of f.
🌐
Byu
acme.byu.edu › 00000181-a756-d9e0-a789-bf7665e10001 › convex-opt-with-cvxpy-pdf pdf
15 CVXPY Lab Objective:
and the variables p1...p6 to define a supply or demand constraint for each location. You may want to · format this as a matrix.
🌐
Stack Overflow
stackoverflow.com › questions › 76526736 › how-to-vectorize-a-matrix-variable-in-cvxpy
python - How to vectorize a matrix variable in CVXPY? - Stack Overflow
I can create a symmetric matrix variable in CVXPY with X = cp.Variable((size_n, size_n), symmetric=True). Is there a way to vectorize the matrix so that I can obtain a size_n*size_n by 1 vector? I ...