What are the Unitary Matrix and its exciting properties?

Phiphat Chomchit
3 min readSep 20, 2023

--

The unitary matrix transformation is used in some concepts like linear algebra and quantum mechanics. The unitary matrix can transform data while preserving some properties of the data matrix such as inner products or singular values. In this article, we will dive deep into some properties of the unitary matrix via mathematical expression and Python code.

Photo by Thomas Vogel on Unsplash

What is the Unitary matrix?

The first thing, we will talk about is the unitary matrix. The unitary has some conditions to be.

The Unitary Matrix definition; Phiphat 2023

Next, I will give you an example. In quantum computing, there is an important unitary matrix called “Hadamard Gate”. I will show you this gate in Python.

The Hadamard Gate; Phiphat 2023
import numpy as np

# Define the Hadamard gate matrix
Hadamard = 1/np.sqrt(2) * np.array([[1, 1],
[1, -1]])
# Try to prove its property
print(Hadamard.T @ Hadamard)
print(Hadamard @ Hadamard.T)
[[1. 0.]
[0. 1.]]

[[1. 0.]
[0. 1.]]

The result of taking the dot product of the transpose (or conjugate transpose) of the gate with the gate is the identity matrix, in accordance with the property mentioned above.

The determinant of the Unitary matrix.

The determinant of the matrix in the geometry perspective shows the volumes or area of the column vectors in the matrix. This section will show you the absolute of determinant of the unitary matrix = 1.

Determinant of the Unitary Matrix; Phiphat 2023

Let’s prove it in code.

np.round(np.abs(np.linalg.det(Hadamard)))
1.0

The Eigenvalues of the Unitary matrix.

In the normal term, a matrix rotates and scales an arrow vector. In special cases, some arrow vectors cannot be rotated by the matrix and just are scaled. These arrows are called eigenvectors and the scalers of arrows are called eigenvalues. We can summarize them in mathematical terms.

Eigenvalue and Eigenvector; Phiphat 2023
The eigenvalue of the unitary matrix; Phiphat 2023

Let’s show the results in code:

np.linalg.eigvals(Hadamard)
array([ 1., -1.])

Preservation of Inner Product

The inner product between two vectors relates to the angle of both. When you apply a unitary transformation to a pair of vectors, the angle between the vectors and their inner product remains unchanged.

The inner product of the Unitary matrix; Phiphat 2023

Let's make the vectors to test the rule.

# create the samples vector u and v
u = np.array([[1],
[0]])

v = np.array([[0],
[1]])

# find the inner product value
np.dot(u.T, v)
array([[0]])

Apply Hadamard gate to them.

# Apply the unitary matrix
Uu = Hadamard @ u
Uv = Hadamard @ v

# find the inner product value
np.dot(Uu.T, Uv)
array([[0]])

Thank you for reading ❤

--

--

Phiphat Chomchit

A Data Scientist and the guy who SIMPLIFIES the COMPLEX PROBLEMS