# 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
import statistics as stat
import matplotlib.pyplot as plt
import numpy as np
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)
mean = stat.mean(temps)
med = stat.median(temps)
mode = stat.mode(temps)
vari = stat.variance(temps)
stdev = stat.stdev(temps)
print (f'mean: {mean}, median: {med}, mode: {mode}, variance: {round(vari,3)}, stdev: {round(stdev,3)}')
mean: 47.2, median: 47.5, mode: 51, variance: 27.511, stdev: 5.245
# Plot the temperatures vs the days as a scatter plot using a red "x"
plt.plot(days, temps, 'rx')
#
# Plot the mean as a horizontal line in green
meanY = np.ones(len(days))*mean
plt.plot(days,meanY, 'g')
#
# Illustrate 1 standard deviation away from the mean by drawing two horizonal lines in
# as dotted blue lines
posSD = meanY + stdev
negSD = meanY - stdev
plt.plot(days, posSD, '--b')
plt.plot(days, negSD, '--b')
plt.show()
import random
ex1 = np.random.randint(100,200,15)
print (ex1)
[163 125 134 109 110 144 119 162 194 130 125 112 198 136 105]
ex2 = np.random.random(15)
print (ex2)
[0.46953663 0.78345028 0.56533861 0.58134321 0.25381739 0.32157812
0.94718052 0.50218986 0.83018022 0.89191069 0.24555046 0.79647283
0.58144398 0.33211071 0.47291965]
ex3 = np.random.random(15)
ex3b = 10 + (40-10)*ex3
print (ex3b)
[15.20216268 12.82945494 37.54381857 26.99217909 34.54741872 29.23014009
32.07016701 27.76116641 29.81646471 11.08526239 27.47229662 37.39814231
30.87952162 34.39078583 31.70090897]
ex4 = np.random.normal(0,1,15)
print (ex4)
[ 0.67902282 0.55054842 -1.27334029 2.36079124 -0.24432229 -1.10520641
0.10820099 1.24929373 -0.85430721 0.29803427 0.94514116 -2.03115358
-1.18523559 -1.29806815 -0.07044632]
ex5 = np.random.normal(20,0.5,15)
print (ex5)
[20.13638687 20.3073728 19.02356188 19.82863427 19.446132 19.59004654
19.56906878 20.13928127 20.20540643 20.47896779 20.3899052 20.12658777
19.51284885 19.50072332 20.1801792 ]