dq.asqarray
asqarray(
x: QArrayLike,
dims: tuple[int, ...] | None = None,
layout: Layout | None = None,
*,
offsets: tuple[int, ...] | 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 spacedims=(n,)
otherwise). -
layout
(dq.dense, dq.dia or None)
–
Matrix layout. If
None
, the default layout isdq.dense
, except for qarrays that are directly returned. -
offsets
–
Offsets of the stored diagonals if
layout==dq.dia
. IfNone
, offsets are determined automatically from the matrix structure. This argument can also be explicitly specified to ensure compatibility with JAX transformations, which require static offset values.
Returns
Qarray representation of the input.
See also
dq.isqarraylike()
: returns True if the input is a qarray-like.
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]]]