To describe the state of a qubit mathematically, complex numbers are arranged into vectors. Classical programming often represents the state of an object using a class with several properties. The state of a system in quantum mechanics is represented by a column vector. This vector contains all the information needed to describe the system at a specific point in time.State Vectors and Dirac NotationWe use a specific notation called Dirac notation (or bra-ket notation) to label these vectors. The standard symbol for a generic quantum state is the Greek letter psi ($\psi$). We enclose this letter in a "ket," written as $|\psi\rangle$.When you see $|\psi\rangle$, it represents a column vector containing complex numbers. For a single qubit, this vector has two components. We call these components amplitudes.$$|\psi\rangle = \begin{bmatrix} \alpha \ \beta \end{bmatrix}$$Here, $\alpha$ and $\beta$ are the complex numbers ($z = a + bi$) we discussed in the previous section.$\alpha$ represents the amplitude associated with the state "0".$\beta$ represents the amplitude associated with the state "1".This two-dimensional vector lives in a specific mathematical structure known as a Hilbert space. For our purposes as engineers, you can think of a Hilbert space as a standard vector space that handles complex numbers and allows us to calculate lengths and angles between vectors.Basis VectorsTo make these vectors useful, we define a standard coordinate system. In a classical 2D graph, you use $x$ and $y$ axes. In quantum computing, our axes are the computational basis states, labeled $|0\rangle$ and $|1\rangle$.These correspond to the classical bit values of 0 and 1, but they are now represented as orthogonal unit vectors:$$|0\rangle = \begin{bmatrix} 1 \ 0 \end{bmatrix}$$$$|1\rangle = \begin{bmatrix} 0 \ 1 \end{bmatrix}$$Any single qubit state $|\psi\rangle$ is a linear combination of these two basis vectors. We can rewrite the state vector equation using this basis:$$|\psi\rangle = \alpha|0\rangle + \beta|1\rangle = \alpha \begin{bmatrix} 1 \ 0 \end{bmatrix} + \beta \begin{bmatrix} 0 \ 1 \end{bmatrix} = \begin{bmatrix} \alpha \ \beta \end{bmatrix}$$This equation expresses the principle of superposition mathematically. The qubit is not just 0 or 1. It is a vector pointing somewhere between the $|0\rangle$ axis and the $|1\rangle$ axis.digraph G { rankdir=LR; bgcolor="transparent"; node [shape=plaintext, fontname="Sans-Serif"]; edge [arrowhead=vee, penwidth=2]; origin [label="", width=0, height=0]; basis0 [label="|0> (1, 0)", fontcolor="#228be6", shape=none]; basis1 [label="|1> (0, 1)", fontcolor="#228be6", shape=none]; psi [label="|Psi>", fontcolor="#fa5252", shape=none]; origin -> basis0 [color="#228be6", label=" x-axis"]; origin -> basis1 [color="#228be6", label=" y-axis"]; origin -> psi [color="#fa5252", label=" State Vector"]; {rank=same; basis0; basis1; psi} }Geometric representation of a state vector relative to the computational basis vectors.The Normalization ConditionIn a physical system, probabilities must sum to exactly 1 (100%). Because the squares of the magnitudes of the amplitudes determine the probability of measurement outcomes, a valid quantum state vector must have a length (or magnitude) of 1.The magnitude of a complex vector is calculated using the Euclidean norm. For our state $|\psi\rangle = \begin{bmatrix} \alpha \ \beta \end{bmatrix}$, the condition is:$$|\alpha|^2 + |\beta|^2 = 1$$Vectors that satisfy this condition are called normalized vectors or unit vectors. If you perform a mathematical operation that results in a vector with a length other than 1, the vector no longer represents a valid physical state for a closed quantum system.For example, the state $|\psi\rangle = \begin{bmatrix} 1 \ 1 \end{bmatrix}$ is not a valid quantum state because $1^2 + 1^2 = 2$. To make it valid, we must normalize it by dividing by the square root of the sum, resulting in $\begin{bmatrix} \frac{1}{\sqrt{2}} \ \frac{1}{\sqrt{2}} \end{bmatrix}$.Implementing State Vectors in PythonWe can use NumPy to handle these linear algebra operations. While specific quantum frameworks like Qiskit handle this under the hood, creating state vectors manually helps clarify the underlying math.We represent the state vectors as NumPy arrays. Note that in NumPy, a simple list [1, 0] creates a 1D array. To properly represent a column vector for linear algebra operations, we often define it as a 2D array with a shape of (2, 1).Here is how to define the basis vectors and a superposition state:import numpy as np # Define the standard basis vectors ket_0 = np.array([[1], [0]]) ket_1 = np.array([[0], [1]]) print(f"Basis |0> shape: {ket_0.shape}") # Create a superposition state: equal probability of 0 and 1 # We use 1/sqrt(2) to ensure normalization alpha = 1 / np.sqrt(2) beta = 1 / np.sqrt(2) psi = alpha * ket_0 + beta * ket_1 print("State vector |psi>:") print(psi)The output confirms that our superposition state is a column vector containing the amplitudes.To verify that a state is valid, we can write a simple function to check if it is normalized. We calculate the sum of the squares of the absolute values of the elements.def is_normalized(state_vector): # Calculate sum of squares of absolute values (probabilities) probabilities = np.abs(state_vector)**2 total_prob = np.sum(probabilities) # Check if sum is approximately 1 (handling floating point precision) return np.isclose(total_prob, 1.0) # Check our psi vector print(f"Is |psi> normalized? {is_normalized(psi)}") # Check an invalid vector invalid_vec = np.array([[1], [1]]) print(f"Is [1, 1] normalized? {is_normalized(invalid_vec)}")Visualizing ProbabilitiesUnderstanding the vector itself is important, but often we want to know the probability distribution it represents. The vector stores the amplitudes, but measurement yields probabilities.The following chart displays the probability distribution for the state $|\psi\rangle = \sqrt{0.2}|0\rangle + \sqrt{0.8}|1\rangle$. Notice that while the vector holds the square roots (the amplitudes), the observation logic cares about the squared values.{"layout": {"title": "Probability Distribution of Measurement", "xaxis": {"title": "Basis State"}, "yaxis": {"title": "Probability", "range": [0, 1]}, "template": "simple_white", "width": 500, "height": 300}, "data": [{"type": "bar", "x": ["|0>", "|1>"], "y": [0.2, 0.8], "marker": {"color": ["#339af0", "#51cf66"]}}]}Probability outcomes derived from the squared magnitudes of the state vector amplitudes.By mastering vectors and understanding normalization, you now have the data structure required to represent a qubit. The next step is applying operations to these vectors to simulate changes in the state.