Skip to content

dq.position

position(dim: int, *, layout: Layout | None = None, hbar: float = 0.5) -> QArray

Returns the position operator \(x = \sqrt{\hbar/2}\,(a^\dag + a)\).

Parameters:

  • dim –

    Dimension of the Hilbert space.

  • layout –

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

  • hbar –

    Value of \(\hbar\) in the commutation relation \([\hat{x}, \hat{p}] = i\hbar\). Common choices are 0.5 (default), 1.0, and 2.0.

Returns:

  • (qarray of shape (dim, dim)) –

    Position operator.

Examples:

>>> dq.position(3)
QArray: shape=(3, 3), dims=(3,), dtype=complex64, layout=dia, ndiags=2
[[    â‹…     0.5  +0.j     â‹…    ]
 [0.5  +0.j     â‹…     0.707+0.j]
 [    â‹…     0.707+0.j     â‹…    ]]