# 14.2.40 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¶
Var.compress(Variable v) -> Variable

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¶
Var.empty(int[] shape) -> Variable

Produce a new empty variable of the given shape.

- Parameters
`shape`

(`int`

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

`Variable`

)

- Var.flatten¶
Var.flatten(Variable v) -> Variable

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¶
Var.hrepeat(Variable v, int n) -> Variable

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¶
Var.hstack(Variable[] v) -> Variable Var.hstack(Variable v1, Variable v2) -> Variable Var.hstack(Variable v1, Variable v2, Variable v3) -> Variable

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¶
Var.promote(Variable v, int nd) -> Variable

Pad the variable shape up to

`nd`

dimensions.

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

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¶
Var.reshape(Variable v, int[] shape) -> Variable Var.reshape(Variable v, int d1, int d2) -> Variable Var.reshape(Variable v, int d1) -> Variable

Create a reshaped view of the given variable.

- Var.stack¶
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) -> Variable

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¶
Var.vrepeat(Variable v, int n) -> Variable

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¶
Var.vstack(Variable[] v) -> Variable Var.vstack(Variable v1, Variable v2) -> Variable Var.vstack(Variable v1, Variable v2, Variable v3) -> Variable

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)`

.