Skip to content

dq.eye

eye(*dims: int, layout: Layout | None = None) -> QArray

Returns the identity operator.

If multiple dimensions are provided \(\mathtt{dims}=(n_1,\dots,n_N)\), it returns the identity operator of the composite Hilbert space of dimension \(n=\prod n_k\): $$ I_n = I_{n_1}\otimes\dots\otimes I_{n_N}. $$

Parameters

  • *dims –

    Hilbert space dimension of each subsystem.

  • layout –

    Matrix layout (dq.dense, dq.dia or None).

Returns

(qarray of shape (n, n)) Identity operator, with n = prod(dims).

Examples

Single-mode \(I_4\):

>>> dq.eye(4)
QArray: shape=(4, 4), dims=(4,), dtype=complex64, layout=dia, ndiags=1
[[1.+0.j   â‹…      â‹…      â‹…   ]
 [  â‹…    1.+0.j   â‹…      â‹…   ]
 [  â‹…      â‹…    1.+0.j   â‹…   ]
 [  â‹…      â‹…      â‹…    1.+0.j]]

Multi-mode \(I_2 \otimes I_3\):

>>> dq.eye(2, 3)
QArray: shape=(6, 6), dims=(2, 3), dtype=complex64, layout=dia, ndiags=1
[[1.+0.j   â‹…      â‹…      â‹…      â‹…      â‹…   ]
 [  â‹…    1.+0.j   â‹…      â‹…      â‹…      â‹…   ]
 [  â‹…      â‹…    1.+0.j   â‹…      â‹…      â‹…   ]
 [  â‹…      â‹…      â‹…    1.+0.j   â‹…      â‹…   ]
 [  â‹…      â‹…      â‹…      â‹…    1.+0.j   â‹…   ]
 [  â‹…      â‹…      â‹…      â‹…      â‹…    1.+0.j]]
See also
  • dq.eye_like(): returns the identity operator in the Hilbert space of the input.