Affine Atoms¶
All of the atoms listed here are affine in their arguments.
MulExpression¶

class
cvxpy.atoms.affine.binary_operators.
MulExpression
(lh_exp, rh_exp)[source]¶ Bases:
cvxpy.atoms.affine.binary_operators.BinaryOperator
Matrix multiplication.
The semantics of multiplication are exactly as those of NumPy’s matmul function, except here multiplication by a scalar is permitted. MulExpression objects can be created by using the ‘*’ operator of the Expression class.
 Parameters
lh_exp (Expression) – The lefthand side of the multiplication.
rh_exp (Expression) – The righthand side of the multiplication.
Bmat¶

cvxpy.atoms.affine.bmat.
bmat
(block_lists)[source]¶ Constructs a block matrix.
Takes a list of lists. Each internal list is stacked horizontally. The internal lists are stacked vertically.
 Parameters
block_lists (list of lists) – The blocks of the block matrix.
 Returns
The CVXPY expression representing the block matrix.
 Return type
CVXPY expression
conv¶

class
cvxpy.atoms.affine.conv.
conv
(lh_expr, rh_expr)[source]¶ Bases:
cvxpy.atoms.affine.affine_atom.AffAtom
1D discrete convolution of two vectors.
The discrete convolution \(c\) of vectors \(a\) and \(b\) of lengths \(n\) and \(m\), respectively, is a length\((n+m1)\) vector where
\[c_k = \sum_{i+j=k} a_ib_j, \quad k=0, \ldots, n+m2.\] Parameters
lh_expr (Constant) – A constant 1D vector or a 2D column vector.
rh_expr (Expression) – A 1D vector or a 2D column vector.
diag¶

cvxpy.atoms.affine.diag.
diag
(expr)[source]¶ Extracts the diagonal from a matrix or makes a vector a diagonal matrix.
 Parameters
expr (Expression or numeric constant) – A vector or square matrix.
 Returns
An Expression representing the diagonal vector/matrix.
 Return type
diff¶

cvxpy.atoms.affine.diff.
diff
(x, k=1, axis=0)[source]¶ Vector of kth order differences.
Takes in a vector of length n and returns a vector of length nk of the kth order differences.
diff(x) returns the vector of differences between adjacent elements in the vector, that is
[x[2]  x[1], x[3]  x[2], …]
diff(x, 2) is the secondorder differences vector, equivalently diff(diff(x))
diff(x, 0) returns the vector x unchanged
index¶

class
cvxpy.atoms.affine.index.
index
(expr, key, orig_key=None)[source]¶ Bases:
cvxpy.atoms.affine.affine_atom.AffAtom
Indexing/slicing into an Expression.
CVXPY supports NumPylike indexing semantics via the Expression class’ overloading of the
[]
operator. This is a lowlevel class constructed by that operator, and it should not be instantiated directly. Parameters
expr (Expression) – The expression indexed/sliced into.
key – The index/slicing key (i.e. expr[key[0],key[1]]).
multiply¶

class
cvxpy.atoms.affine.binary_operators.
multiply
(lh_expr, rh_expr)[source]¶ Bases:
cvxpy.atoms.affine.binary_operators.MulExpression
Multiplies two expressions elementwise.
promote¶

cvxpy.atoms.affine.promote.
promote
(expr, shape)[source]¶ Promote a scalar expression to a vector/matrix.
 Parameters
expr (Expression) – The expression to promote.
shape (tuple) – The shape to promote to.
 Raises
ValueError – If
expr
is not a scalar.
reshape¶

class
cvxpy.atoms.affine.reshape.
reshape
(expr, shape)[source]¶ Bases:
cvxpy.atoms.affine.affine_atom.AffAtom
Reshapes the expression.
Vectorizes the expression then unvectorizes it into the new shape. The entries are reshaped and stored in columnmajor order, also known as Fortran order.
 Parameters
expr (Expression) – The expression to promote.
shape (tuple or int) – The shape to promote to.
sum¶

cvxpy.atoms.affine.sum.
sum
(expr, axis=None, keepdims=False)[source]¶ Sum the entries of an expression.
 Parameters
expr (Expression) – The expression to sum the entries of.
axis (int) – The axis along which to sum.
keepdims (bool) – Whether to drop dimensions after summing.
trace¶

class
cvxpy.atoms.affine.trace.
trace
(expr)[source]¶ Bases:
cvxpy.atoms.affine.affine_atom.AffAtom
The sum of the diagonal entries of a matrix.
 Parameters
expr (Expression) – The expression to sum the diagonal of.
upper_tri¶

class
cvxpy.atoms.affine.upper_tri.
upper_tri
(expr)[source]¶ Bases:
cvxpy.atoms.affine.affine_atom.AffAtom
The vectorized strictly uppertriagonal entries.
The vectorization is performed by concatenating (partial) rows. For example, if ``` A = np.array([[10, 11, 12, 13],
[14, 15, 16, 17], [18, 19, 20, 21], [22, 23, 24, 25]])
` then we have `
upper_tri(A).value == np.array([11, 12, 13, 16, 17, 21]) ```
vec¶

cvxpy.atoms.affine.vec.
vec
(X)[source]¶ Flattens the matrix X into a vector in columnmajor order.
 Parameters
X (Expression or numeric constant) – The matrix to flatten.
 Returns
An Expression representing the flattened matrix.
 Return type