# 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
list = [6, 8, 12, 14]
stat.stdev ( list)
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)
temps_array = np.array (temps)
print (stat.mean (temps_array))
print (stat.median ( temps_array))
print (stat.mode (temps_array ))
print (stat.variance(temps_array))
print (format (stat.stdev(temps_array), ".3f"))
47
47.5
51
27
5.196
temps = [45, 51, 38, 42, 47, 51, 52, 55, 48, 43]
n = len(temps)
days = np.linspace(1,n,n)
x_axis = days
y_temp = temps_array
mean = (stat.mean (temps_array))
y_mean = ((np.ones (len (temps)))* mean)
sdev = (format (stat.stdev(temps_array), ".3f"))
plt.plot (x_axis, y_temp, "rx")
plt.plot (x_axis, y_mean, "g")
y_sdev = ((np.ones (len (temps)))* sdev)
y_SD = np.array ((format (stat.stdev(temps_array), ".3f"))* (np.ones (len (temps))))
plt.plot (x_axis, y_SD, "--b")
# Plot the temperatures vs the days as a scatter plot using a red "x"
#
# Plot the mean as a horizontal line in green
#
# Illustrate 1 standard deviation away from the mean by drawing two horizonal lines in
# as dotted blue lines
plt.show()
import random
n = 15
for x in range (0, n):
print (random.randint(100, 200))
136
158
117
129
115
108
187
184
133
138
165
178
139
146
193
import numpy as np
print (np.random.randint (low= 100, high= 200, size= 15))
[140 135 125 124 180 109 134 191 106 173 185 190 164 180 170]
n = 15
for x in range (0,n):
print (random.random ())
0.7918656234232712
0.5032059013463318
0.446777351294978
0.2316154782742148
0.39599249965110206
0.7879881766323027
0.6045649888025908
0.7356252782800463
0.28451916879985906
0.7273939601648737
0.4975644509901058
0.19527879678093019
0.9701620921331056
0.6457627410921728
0.5339912574407337
print (np.random.uniform (size= 15))
[0.18891344 0.62735694 0.84677336 0.02144266 0.50041176 0.19152751
0.76858668 0.3538407 0.81473376 0.01427286 0.76110407 0.11533108
0.05557543 0.45485774 0.85052647]
for i in range (0, 16):
x = random.random ()
y = 10 + 30 * x
print (y)
27.30336594674548
15.461556416572503
28.66447361961306
27.06624876125416
26.765226803736304
32.07174167258533
18.57587033219572
21.260545094610023
17.76015105796721
37.18393061909549
27.055767827994735
20.938516212270635
22.096385166214965
14.957613445950564
36.5407770752213
39.6232485986981
x = np.random.uniform (size= 15)
y = 10 + 30 * x
print (y)
[12.85081467 33.40052925 10.52717153 24.69446489 25.44589097 31.88193122
37.57572408 10.86767468 33.58095423 13.49727164 15.55618092 31.35461947
17.57024326 26.45542061 37.61917164]
x = np.random.normal (size= 15)
print (x)
[-4.74854566 0.13288849 0.35877569 -0.73848092 -0.92953814 0.6138793
-1.52934851 0.25013881 0.86279088 -0.41811751 -1.33159171 -1.20996427
-1.06603959 -0.10285198 -0.66765294]
y = 20 + x*(0.5)
print (y)
[17.62572717 20.06644425 20.17938785 19.63075954 19.53523093 20.30693965
19.23532575 20.12506941 20.43139544 19.79094125 19.33420415 19.39501786
19.46698021 19.94857401 19.66617353]