cirq.dirac_notation
Returns the state vector as a string in Dirac notation.
cirq.dirac_notation(
state_vector: np.ndarray,
decimals: int = 2,
qid_shape: Optional[Tuple[int, ...]] = None
) -> str
For example:
state_vector = np.array([1/np.sqrt(2), 1/np.sqrt(2)], dtype=np.complex64)
print(cirq.dirac_notation(state_vector))
0.71|0⟩ + 0.71|1⟩
Args |
state_vector
|
A sequence representing a state vector in which
the ordering mapping to qubits follows the standard Kronecker
convention of numpy.kron (big-endian).
|
decimals
|
How many decimals to include in the pretty print.
|
qid_shape
|
specifies the dimensions of the qudits for the input
state_vector . If not specified, qubits are assumed and the
state_vector must have a dimension a power of two.
|
Returns |
A pretty string consisting of a sum of computational basis kets
and non-zero floats of the specified accuracy.
|
Raises |
ValueError
|
If there is a shape mismatch between state_vector and qid_shape.
Otherwise, when qid_shape is not mentioned and length of state_vector
is not a power of 2.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-06-27 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-06-27 UTC."],[],[]]