a = 11
b = 23
c = a + b
print('%d + %d = %d' % (a, b, c) )
11 + 23 = 34
import math
a = 2.0
b = math.sqrt(a)
print('sqrt(%f) = %f' % (a, b) )
sqrt(2.000000) = 1.414214
a = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]
print(a, ' --> sum =', sum(a))
b = []
for x in a:
b.append(x*x)
print(b)
[1.0, 2.0, 3.0, 4.0, 5.0] --> sum= 15.0 [1.0, 4.0, 9.0, 16.0, 25.0]
import numpy as np
a = np.arange(0.0, 10.0, 1.0)
b = a*a
print(a)
print(b)
[0. 1. 2. 3. 4. 5. 6. 7. 8. 9.] [ 0. 1. 4. 9. 16. 25. 36. 49. 64. 81.]
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0.0, 100.0, 0.1)
y = np.sin(x)
plt.plot(x, y)
plt.xlabel('X')
plt.ylabel('Y')
plt.show()
plt.hist(y, bins=100, range=(-1.0, 1.0))
plt.xlabel('Y')
plt.ylabel('Counts')
plt.show()
fout = open('../data/2022ALH1_sindata.dat', 'w')
for i in range(len(x)):
fout.write('%10.5f %10.5f\n' % (x[i], y[i]) )
fout.close()