matrix_ops.vec

Performs the vec operation on a matrix.

Functions

vec(mat)

Perform the vec operation on a matrix.

Module Contents

matrix_ops.vec.vec(mat)

Perform the vec operation on a matrix.

For more info, see Section: The Operator-Vector Correspondence from [1].

The function reorders the given matrix into a column vector by stacking the columns of the matrix sequentially.

For instance, for the following matrix:

\[\begin{split}X = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}\end{split}\]

it holds that

\[\text{vec}(X) = \begin{pmatrix} 1 & 3 & 2 & 4 \end{pmatrix}^T\]

More formally, the vec operation is defined by

\[\text{vec}(E_{a,b}) = e_a \otimes e_b\]

for all \(a\) and \(b\) where

\[\begin{split}E_{a,b}(c,d) = \begin{cases} 1 & \text{if} \ (c,d) = (a,b) \\ 0 & \text{otherwise} \end{cases}\end{split}\]

for all \(c\) and \(d\) and where

\[\begin{split}e_a(b) = \begin{cases} 1 & \text{if} \ a = b \\ 0 & \text{if} \ a \not= b \end{cases}\end{split}\]

for all \(a\) and \(b\).

Examples

Consider the following matrix

\[\begin{split}A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}\end{split}\]

Performing the \(\text{vec}\) operation on \(A\) yields

\[\text{vec}(A) = \left[1, 3, 2, 4 \right]^{T}.\]
>>> from toqito.matrix_ops import vec
>>> import numpy as np
>>> X = np.array([[1, 2], [3, 4]])
>>> vec(X)
array([[1],
       [3],
       [2],
       [4]])

See also

unvec()

References

[1]

John Watrous. The Theory of Quantum Information. Cambridge University Press, 2018. URL: https://johnwatrous.com/wp-content/uploads/TQI.pdf, doi:10.1017/9781316848142.

Parameters:

mat (numpy.ndarray) – The input matrix.

Returns:

The vec representation of the matrix.

Return type:

numpy.ndarray