# import statistics library as stat
#
import statistics as stat
#
# import matplotlib.pyplot as plt and NumPy as np
import matplotlib.pyplot as plt
import numpy as np
numbers = [ 6, 8, 12, 14 ]
stat.stdev(numbers)
temps = [45, 51, 38, 42, 47, 51, 52, 55, 48, 43]
n = len(temps)
# for plotting purposes I have added an array of days from 1 to 10
days = np.linspace(1,n,n)
print (stat.mean (temps))
print (stat.median (temps))
print (stat.mode (temps))
print (stat.variance (temps))
print (stat.pvariance (temps))
print (stat.stdev (temps))
47.2
47.5
51
27.511111111111113
24.76
5.2451035367389185
import matplotlib.pyplot as plt
# Plot the temperatures vs the days as a scatter plot using a red "x"
temps = [45, 51, 38, 42, 47, 51, 52, 55, 48, 43]
x = np.array (temps)
y= np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
plt.scatter (x,y)
plt.xlabel('Temperature')
plt.ylabel('Days')
plt.plot (x, y, 'rx')
#
# Plot the mean as a horizontal line in green
plt.axhline(y=47.2, color='g', linestyle='-')
#
# Illustrate 1 standard deviation away from the mean by drawing two horizonal lines in
# as dotted blue lines
plt.axhline(y=52.445, color='b', linestyle=':')
plt.axhline(y=41.755, color='b', linestyle=':')
plt.show()
import numpy as np
np.random.seed(12345)
x = np.random.randint (low = 100, high = 200, size = 15)
print (x)
[141 118 150 182 157 146 158 123 121 107 181 163 100 190 144]
x = np.random.uniform (size = 15)
print (x)
[0.17805301 0.53144988 0.16774223 0.76881392 0.92817055 0.60949366
0.15018349 0.4896267 0.37734495 0.84860141 0.91109723 0.38384872
0.3154959 0.56839415 0.18781804]
xp = np.random.uniform (size = 15)
x = 15 + (40-10)*x
print (x)
[20.34159018 30.94349653 20.03226686 38.06441755 42.84511647 33.28480974
19.50550484 29.68880111 26.32034861 40.45804236 42.33291686 26.51546163
24.4648771 32.05182458 20.63454105]
x = np.random.normal (size = 15)
print (x)
[-1.6515933 0.2217555 -0.8382103 1.39655345 -1.55377469 -0.00768041
1.33575284 -1.29663763 1.06799001 -0.74342928 0.50028557 0.4001
-0.25978066 0.65081955 0.89675774]
x = np.random.normal (size = 15)
x = 20 + (.5)*x
print (x)
[19.27447755 20.98023573 20.0819352 20.19439094 20.47043997 20.83035986
20.32102203 20.20949396 19.87038381 19.81500922 19.97773598 20.05631332
20.17004413 21.0003904 20.07244828]