Skip to content

dq.asqarray

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

Converts a qarray-like into a qarray.

Parameters

  • x –

    Object to convert.

  • 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. If None, the default layout is dq.dense, except for qarrays that are directly returned.

Returns

Qarray representation of the input.

See also

Examples

>>> dq.asqarray([[1, 0], [0, -1]])
QArray: shape=(2, 2), dims=(2,), dtype=int32, layout=dense
[[ 1  0]
 [ 0 -1]]
>>> dq.asqarray([[1, 0], [0, -1]], layout=dq.dia)
QArray: shape=(2, 2), dims=(2,), dtype=int32, layout=dia, ndiags=1
[[ 1  â‹…]
 [ â‹… -1]]
>>> dq.asqarray([qt.sigmax(), qt.sigmay(), qt.sigmaz()])
QArray: shape=(3, 2, 2), dims=(2,), dtype=complex64, layout=dense
[[[ 0.+0.j  1.+0.j]
  [ 1.+0.j  0.+0.j]]

 [[ 0.+0.j  0.-1.j]
  [ 0.+1.j  0.+0.j]]

 [[ 1.+0.j  0.+0.j]
  [ 0.+0.j -1.+0.j]]]