toqito.matrix_ops.unvec
- toqito.matrix_ops.unvec(vector, shape=None)[source]
Perform the unvec operation on a vector to obtain a matrix [Rigetti2020].
Takes a column vector and transforms it into a
shape[0]-by-shape[1]matrix. This operation is the inverse ofvecoperation intoqito.For instance, for the following column vector
\[\begin{split}u = \begin{pmatrix} 1 \\ 3 \\ 2 \\ 4 \end{pmatrix},\end{split}\]it holds that
\[\begin{split}\text{unvec}(u) = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}\end{split}\]More formally, the vec operation is defined by
\[\text{unvec}(e_a \otimes e_b) = E_{a,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\).
This function has been adapted from [Rigetti20].
Examples
Consider the following vector
\[\begin{split}u = \begin{pmatrix} 1 \\ 3 \\ 2 \\ 4 \end{pmatrix}\end{split}\]Performing the \(\text{unvec}\) operation on \(u\) yields
\[\begin{split}\text{unvec}(u) = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}\end{split}\]>>> from toqito.matrix_ops import unvec >>> import numpy as np >>> u = np.array([1, 2, 3, 4]) >>> unvec(u) [[1 2] [3 4]]
See also
References
[Rigetti2020]Forest Benchmarking (Rigetti). https://github.com/rigetti/forest-benchmarking
- Parameters:
vector – A (
shape[0] * shape[1])-by-1 numpy array.shape – The shape of the output matrix; by default, the matrix is assumed to be square.
- Returns:
Returns a
shape[0]-by-shape[1]matrix.