Numpy Python

Using Numpy to Study Pauli Matrices

Numpy has a lot of built in functions for linear algebra which is useful to study Pauli matrices conveniently.

Define Pauli matrices

$$ \sigma_1 = \begin{pmatrix} 0 & 1\\ 1 & 0 \end{pmatrix}, \sigma_2 = \begin{pmatrix} 0 & -i\\ i & 0 \end{pmatrix}, \sigma_3 = \begin{pmatrix} 1 & 0\\ 0 & -1 \end{pmatrix} $$
s1 = np.matrix([[0,1],[1,0]])
s2 = np.matrix([[0,-1j],[1j,0]])
s3 = np.matrix([[1,0],[0,-1]])

You can find out the square of Pauli matrices using **. The result is always identity matrices

$$ \sigma_1^2 = \sigma_2^2 = \sigma_3^2 = 1 $$
print('s1*s1 = ',s1**2)
print('s2*s2 = ',s2**2)
print('s3*s3 = ',s3**2)
Output: s1*s2+s2*s1 = [[0.+0.j 0.+0.j] [0.+0.j 0.+0.j]] s1*s3+s3*s1 = [[0 0] [0 0]] s2*s3+s3*s2 = [[0.+0.j 0.+0.j] [0.+0.j 0.+0.j]]

Commutators and Anti-commutators

You can define the commutator and anticommutator relations using *

$$ \{\sigma_i,\sigma_j\} = \sigma_i * \sigma_j + \sigma_j*\sigma_i = 0 $$
print('s1*s2+s2*s1 = ',s1*s2+s2*s1)
print('s1*s3+s3*s1 = ',s1*s3+s3*s1)
print('s2*s3+s3*s2 = ',s2*s3+s3*s2)
Output: s1*s2+s2*s1 = [[0.+0.j 0.+0.j] [0.+0.j 0.+0.j]] s1*s3+s3*s1 = [[0 0] [0 0]] s2*s3+s3*s2 = [[0.+0.j 0.+0.j] [0.+0.j 0.+0.j]] $$ [ \sigma_i,\sigma_j ] = \sigma_i * \sigma_j – \sigma_j*\sigma_i = 2j\epsilon _{ijk} $$
print('s1*s2-s2*s1 = ',s1*s2-s2*s1)
print('s2*s3-s3*s2 = ',s2*s3-s3*s2)
print('s3*s1-s1*s3 = ',s3*s1-s1*s3)
Output: s1*s2+s2*s1 = [[0.+0.j 0.+0.j] [0.+0.j 0.+0.j]] s1*s3+s3*s1 = [[0 0] [0 0]] s2*s3+s3*s2 = [[0.+0.j 0.+0.j] [0.+0.j 0.+0.j]]

Trace

The trace is the sum of diagonal values of a matrices. It is always equal to the sum of eigenvalues. The trace of Pauli matrices are zero as shown below:

$$ Tr(\sigma_i) = 0 $$
print('Trace of s1 = ',np.trace(s1))
print('Trace of s2 = ',np.trace(s2))
print('Trace of s3 = ',np.trace(s3))
Output: Trace of s1 = 0 Trace of s2 = 0j Trace of s3 = 0

Eigenvectors and Eigenvalues

The eigenvalues of Pauli matrices are +1 and -1. You can readily compute the eigenvalues and eigenvectors of Pauli matrices using the linalg packages

print(np.linalg.eig(s1))
print(np.linalg.eig(s2))
print(np.linalg.eig(s3))
Output: (array([ 1., -1.]), matrix([[ 0.70710678, -0.70710678], [ 0.70710678, 0.70710678]])) (array([ 1.+0.j, -1.+0.j]), matrix([[-0. -0.70710678j, 0.70710678+0.j ], [ 0.70710678+0.j (array([ 1., -1.]), matrix([[1., 0.], [0., 1.]]))

References:

Relevant Courses

May 24, 2021