# Affine Atoms¶

All of the atoms listed here are affine in their arguments.

class cvxpy.atoms.affine.add_expr.AddExpression(arg_groups)[source]

Bases: cvxpy.atoms.affine.affine_atom.AffAtom

The sum of any number of expressions.

## 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 left-hand side of the multiplication.

• rh_exp (Expression) – The right-hand side of the multiplication.

## DivExpression¶

class cvxpy.atoms.affine.binary_operators.DivExpression(lh_expr, rh_expr)[source]

Bases: cvxpy.atoms.affine.binary_operators.BinaryOperator

Division by scalar.

Can be created by using the / operator of expression.

## 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+m-1)$$ vector where

$c_k = \sum_{i+j=k} a_ib_j, \quad k=0, \ldots, n+m-2.$
Parameters
• lh_expr (Constant) – A constant 1D vector or a 2D column vector.

• rh_expr (Expression) – A 1D vector or a 2D column vector.

## cumsum¶

class cvxpy.atoms.affine.cumsum.cumsum(expr, axis=0)[source]

Bases: cvxpy.atoms.affine.affine_atom.AffAtom, cvxpy.atoms.axis_atom.AxisAtom

Cumulative sum.

expr

The expression being summed.

Type

CVXPY expression

axis

The axis to sum across if 2D.

Type

int

## 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

Expression

## 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 n-k 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 second-order differences vector, equivalently diff(diff(x))

diff(x, 0) returns the vector x unchanged

## hstack¶

cvxpy.atoms.affine.hstack.hstack(arg_list)[source]

Horizontal concatenation of an arbitrary number of Expressions.

Parameters

arg_list (list of Expression) – The Expressions to concatenate.

## 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 NumPy-like indexing semantics via the Expression class’ overloading of the [] operator. This is a low-level 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]]).

## kron¶

class cvxpy.atoms.affine.kron.kron(lh_expr, rh_expr)[source]

Bases: cvxpy.atoms.affine.affine_atom.AffAtom

Kronecker product.

## matmul¶

cvxpy.atoms.affine.binary_operators.matmul(lh_exp, rh_exp)[source]

Matrix multipliction.

## multiply¶

class cvxpy.atoms.affine.binary_operators.multiply(lh_expr, rh_expr)[source]

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 column-major 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.

## transpose¶

class cvxpy.atoms.affine.transpose.transpose(expr, axes=None)[source]

Bases: cvxpy.atoms.affine.affine_atom.AffAtom

Transpose an expression.

## NegExpression¶

class cvxpy.atoms.affine.unary_operators.NegExpression(expr)[source]

Bases: cvxpy.atoms.affine.unary_operators.UnaryOperator

Negation of an expression.

## upper_tri¶

class cvxpy.atoms.affine.upper_tri.upper_tri(expr)[source]

Bases: cvxpy.atoms.affine.affine_atom.AffAtom

The vectorized strictly upper triagonal entries.

## vec¶

cvxpy.atoms.affine.vec.vec(X)[source]

Flattens the matrix X into a vector in column-major order.

Parameters

X (Expression or numeric constant) – The matrix to flatten.

Returns

An Expression representing the flattened matrix.

Return type

Expression

## vstack¶

cvxpy.atoms.affine.vstack.vstack(arg_list)[source]

Wrapper on vstack to ensure list argument.