-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkron.py
More file actions
26 lines (22 loc) · 722 Bytes
/
kron.py
File metadata and controls
26 lines (22 loc) · 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Author: Alex Gezerlis
# Numerical Methods in Physics with Python (CUP, 2020)
import numpy as np
def paulimatrices():
sigx = np.array([0.,1,1,0]).reshape(2,2)
sigy = np.array([0.,-1j,1j,0]).reshape(2,2)
sigz = np.array([1.,0,0,-1]).reshape(2,2)
return sigx, sigy, sigz
def kron(U,V):
n = U.shape[0]
p = V.shape[0]
W = np.zeros((n*p,n*p), dtype=np.complex64)
for i in range(n):
for k in range(n):
for j in range(p):
for l in range(p):
W[p*i+j,p*k+l] = U[i,k]*V[j,l]
return W
if __name__ == '__main__':
sigx, sigy, sigz = paulimatrices()
allones = np.ones((3,3))
kronprod = kron(sigx,allones); print(kronprod.real)