Numpy and Scipy
Numpy and Scipy
Hendrik Weimer
1. Introduction to Python
2. SciPy/NumPy packages
3. Plotting and fitting
4. QuTiP: states and operators
5. Ground state problems
6. Non-equilibrium dynamics: quantum quenches
7. Quantum master equations
8. Generation of squeezed states
9. Quantum computing
10. Grover’s algorithm and quantum machine learning
11. Student presentations
a = [1, 0]
b = [0, 1]
print(a+b)
Output:
[1, 0, 0, 1]
import numpy as np
a = np.array([1, 0])
b = np.array([0, 1])
print(a+b)
Output:
[1 1]
A = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
print(A[0,0])
print(A[:,0])
print(A.trace())
Output:
1
[1 4 7]
15
A = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
print(A*A)
print(A.matmul(A)) # Python 3.6: A @ A
Output:
[[ 1 4 9]
[16 25 36]
[49 64 81]]
[[ 30 36 42]
[ 66 81 96]
[102 126 150]]
for x in np.arange(0,1,0.2):
print(x)
print()
print(np.arange(4,4.4,0.1))
Output:
0.0
0.2
0.4
0.6
0.8
Output:
data = np.loadtxt("data.txt")
16 sub-packages, including:
I Integration
I Interpolation
I Linear algebra
I Optimization
I Special functions
Stefan-Boltzmann law:
(kB T )4
P/A = σ
h3 c2
Z∞
x3
σ = 2π dx
ex − 1
0
I = integrate.quadrature(lambda x: x^3/(exp(x)-1), 0,
float(’inf’))
Output:
(6.49393940226683, 1.877560045914113e-11)
40.80262463803753 7.105427357601002e-15
Output:
[ 2. -2. 9.]
Output:
[ 1.30644001]
[ 3.83746711]
Output:
Output:
[[ 0.70710678+0.j 0.00000000+0.70710678j]
[ 0.00000000+0.70710678j 0.70710678+0.j ]]