matrix_ops.outer_product
¶
Outer product operation.
Module Contents¶
Functions¶
|
Compute the outer product \(|v_1\rangle\langle v_2|\) of two vectors. |
- matrix_ops.outer_product.outer_product(v1, v2)¶
Compute the outer product \(|v_1\rangle\langle v_2|\) of two vectors.
The outer product is calculated as follows [1] :
\[\begin{split}\left|\begin{pmatrix}a_1\\\vdots\\a_n\end{pmatrix}\right\rangle\left\langle\begin{pmatrix}b_1\\\vdots\\b_n\end{pmatrix}\right|=\begin{pmatrix}a_1\\\vdots\\a_n\end{pmatrix}\begin{pmatrix}b_1&\cdots&b_n\end{pmatrix}=\begin{pmatrix}a_1b_1&\cdots&a_1b_n\\\vdots&\ddots&\vdots\\a_1b_n&\cdots&a_nb_n\end{pmatrix}\end{split}\]Example
The outer product of the vectors \(v1 = \begin{pmatrix}1 \\ 2 \\ 3 \end{pmatrix}\) and \(v2 = \begin{pmatrix}4 \\ 5 \\ 6 \ \end{pmatrix}\) looks as follows:
\[\begin{split}\left|\begin{pmatrix} 1 \\ 2 \\ 3 \end{pmatrix}\right\rangle \left\langle \begin{pmatrix} 4 \\ 5 \\ 6 \end{pmatrix}\right|= \begin{pmatrix} 1 \\ 2 \\ 3 \end{pmatrix} \begin{pmatrix} 4 & 5 & 6 \end{pmatrix}= \begin{pmatrix} 1 \times 4 & 1 \times 5 & 1 \times 6 \\ 2 \times 4 & 2 \times 5 & 2 \times 6 \\ 3 \times 4 & 3 \times 5 & 3 \times 6 \end{pmatrix}= \begin{pmatrix} 4 & 5 & 6 \\ 8 & 10 & 12 \\ 12 & 15 & 18 \end{pmatrix}\end{split}\]In
toqito
, this looks like this:>>> import numpy as np >>> from toqito.matrix_ops import outer_product >>> v1, v2 = np.array([1,2,3]), np.array([4,5,6]) >>> outer_product(v1,v2) array([[ 4, 5, 6], [ 8, 10, 12], [12, 15, 18]])
References
[1]Wikipedia. Outer product. https://en.wikipedia.org/wiki/Outer_product.
- Raises:
ValueError – Vector dimensions are mismatched.
- Parameters:
v1 (numpy.ndarray) – v1 and v2, both vectors of dimensions \((n,1)\) where \(n>1\).
v2 (numpy.ndarray) – v1 and v2, both vectors of dimensions \((n,1)\) where \(n>1\).
- Returns:
The computed outer product.
- Return type:
numpy.ndarray