# 14.2.41 Class Var¶

- mosek.fusion.Var¶
Contains several static methods for manipulating variable objects and creating new variables from old ones.

Primal and dual solution values and additional operations on variables are available from the

`Variable`

class.- Static members
Var.Compress – Reshape a variable object by removing all dimensions of size 1.

Var.Empty – Produce a new empty variable of the given shape.

Var.Flatten – Create a one-dimensional logical view of a variable object.

Var.Hrepeat – Repeat a variable a number of times in the second dimension.

Var.Hstack – Stack a list of variables horizontally (i.e. along the second dimension).

Var.Promote – Pad variable shape.

Var.Repeat – Repeat a variable a number of times in the given dimension.

Var.Reshape – Create a reshaped view of the given variable.

Var.Stack – Stack a list of variables in an arbitrary dimension.

Var.Vrepeat – Repeat a variable a number of times in the first dimension.

Var.Vstack – Stack a list of variables vertically (i.e. along the first dimension).

- Var.Compress¶
Variable Var.Compress(Variable v)

Reshape a variable object by removing all dimensions of size 1. The result contains the same number of elements, but all dimensions are larger than 1 (except if the original variable contains exactly one element).

- Var.Empty¶
Variable Var.Empty(int[] shape)

Produce a new empty variable of the given shape.

- Parameters
`shape`

(`int`

[]) – The shape of a variable.- Return
(

`Variable`

)

- Var.Flatten¶
Variable Var.Flatten(Variable v)

Create a one-dimensional

`Variable`

object that represents a*logical*view of the \(k-\)dimensional variable \(V\). The \(V\) matrix is traversed starting from the innermost dimension. For a two-dimensional matrix this means it is traversed row after row.The returned view is a one-dimensional array of size equal to the product of dimensions of \(V\).

- Var.Hrepeat¶
Variable Var.Hrepeat(Variable v, int n)

Repeat a variable a number of times in the second dimension. This is equivalent to horizontal stacking of \(n\) copies of the variable; see

`Var.Hstack`

.

- Var.Hstack¶
Variable Var.Hstack(Variable[] v) Variable Var.Hstack(Variable v1, Variable v2) Variable Var.Hstack(Variable v1, Variable v2, Variable v3)

Stack a list of variables horizontally (i.e. along the second dimension). The variables must have the same shape, except for the second dimension.

For example, if \(x^1,x^2,x^3\) are three one-dimensional variables of length \(n\) then their horizontal stack is the matrix variable

\[\begin{split}\left[ \begin{array}{ccc} | & | & | \\ x^1 & x^2 & x^3 \\ | & | & | \end{array}\right]\end{split}\]of shape

`(n,3)`

.

- Var.Promote¶
Variable Var.Promote(Variable v, int nd)

Pad the variable shape up to

`nd`

dimensions.

- Var.Repeat¶
Variable Var.Repeat(Variable v, int dim, int n) Variable Var.Repeat(Variable v, int n)

Repeat a variable a number of times in the given dimension. If

`dim`

is non-negative this is equivalent to stacking \(n\) copies of the variable in dimension`dim`

; see`Var.Stack`

.If

`dim`

is negative then a new dimension is added in front, so the new variable has shape`(n, v.shape())`

.The default is repeating in the first dimension as in

`Var.Vrepeat`

.

- Var.Reshape¶
Variable Var.Reshape(Variable v, int[] shape) Variable Var.Reshape(Variable v, int d1, int d2) Variable Var.Reshape(Variable v, int d1)

Create a reshaped view of the given variable.

- Var.Stack¶
Variable Var.Stack(int dim, Variable v1, Variable v2) Variable Var.Stack(int dim, Variable v1, Variable v2, Variable v3) Variable Var.Stack(int dim, Variable[] v) Variable Var.Stack(Variable v1, Variable v2, int dim) Variable Var.Stack(Variable v1, Variable v2, Variable v3, int dim) Variable Var.Stack(Variable[] v, int dim) Variable Var.Stack(Variable[][] vlist)

Stack a list of variables along an arbitrary dimension. All variables must have the same shape, except for dimension

`dim`

.For example, suppose \(x,y\) are two matrix variables of shape \(n\times m\). Then stacking them in the first dimension produces a matrix variable of shape

`(2n,m)`

:\[\begin{split}\left[\begin{array}{c}x\\ y\end{array}\right],\end{split}\]stacking them in the second dimension produces a matrix variable of shape

`(n,2m)`

:\[\left[\begin{array}{cc}x & y\end{array}\right],\]and stacking them in the third dimension produces a three-dimensional variable of shape

`(n,m,2)`

.The version which takes a two-dimensional array of variables constructs a block matrix variable with the given variables as blocks. The dimensions of the blocks must be suitably compatible. The variables may be more than two-dimensional, if they have the same size in the remaining dimensions; the block stacking still takes place in the first and second dimension.

- Parameters
- Return
(

`Variable`

)

- Var.Vrepeat¶
Variable Var.Vrepeat(Variable v, int n)

Repeat a variable a number of times in the first dimension. This is equivalent to vertically stacking of \(n\) copies of the variable; see

`Var.Vstack`

.

- Var.Vstack¶
Variable Var.Vstack(Variable[] v) Variable Var.Vstack(Variable v1, Variable v2) Variable Var.Vstack(Variable v1, Variable v2, Variable v3)

Stack a list of variables vertically (i.e. along the first dimension). The variables must have the same shape, except for the first dimension.

For example, if \(y^1,y^2,y^3\) are three horizontal vector variables of length \(n\) (and shape

`(1,n)`

) then their vertical stack is the matrix variable\[\begin{split}\left[ \begin{array}{c}- y^1 - \\ - y^2 - \\ - y^3 - \end{array}\right]\end{split}\]of shape

`(3,n)`

.