matrix_ops.unvec

Unvec operation.

Module Contents

Functions

unvec(vector[, shape])

Perform the unvec operation on a vector to obtain a matrix [1].

matrix_ops.unvec.unvec(vector, shape=None)

Perform the unvec operation on a vector to obtain a matrix [1].

Takes a column vector and transforms it into a shape[0]-by-shape[1] matrix. This operation is the inverse of vec operation in toqito.

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 [1].

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)
array([[1, 3],
       [2, 4]])

See also

vec

References

[1] (1,2,3)

Rigetti. Forest benchmarking. https://github.com/rigetti/forest-benchmarking.

Parameters:
  • vector (numpy.ndarray) – A (shape[0] * shape[1])-by-1 numpy array.

  • shape (list[int]) – The shape of the output matrix; by default, the matrix is assumed to be square.

Returns:

Returns a shape[0]-by-shape[1] matrix.

Return type:

numpy.ndarray