Skip to content

dq.eye_like

eye_like(
    x: QArrayLike, dims: tuple[int, ...] | None = None, layout: Layout | None = None
) -> QArray

Returns the identity operator in the Hilbert space of the input.

Parameters

  • x (qarray-like of shape (..., n, 1) or (..., 1, n) or (..., n, n)) –

    Ket, bra or operator.

  • dims (tuple of ints or None) –

    Dimensions of each subsystem in the composite system Hilbert space tensor product. Defaults to None (x.dims if available, single Hilbert space dims=(n,) otherwise).

  • layout (dq.dense, dq.dia or None) –

    Matrix layout.

Returns

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

Examples

Single-mode \(I_4\):

>>> a = dq.destroy(4)
>>> dq.eye_like(a)
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\):

>>> a, b = dq.destroy(2, 3)
>>> dq.eye_like(a)
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(): returns the identity operator.