# 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
temps = [45, 51, 38, 42, 47, 51, 52, 55, 48, 43]
meantemps = stat.mean(temps)
mediantemps = stat.median(temps)
modetemps = stat.mode(temps)
vartemps = stat.variance(temps)
vartemps = round(vartemps, 3)
sdtemps = stat.stdev(temps)
sdtemps = round(sdtemps, 3)
print(f"The mean is {meantemps}, the median is {mediantemps},")
print(f"the mode is {modetemps}, the variance is {vartemps} & the standard deviation is {sdtemps}")
# for plotting purposes I have added an array of days from 1 to 10
days = []
days = np.linspace(1,10,10)
print(days)
The mean is 47.2, the median is 47.5,
the mode is 51, the variance is 27.511 & the standard deviation is 5.245
[ 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.]
# 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
meanarr = np.ones(len(days))
meanarr = meanarr*meantemps
plt.plot(days,meanarr,'g')
#
# Illustrate 1 standard deviation away from the mean by drawing two horizonal lines in
# as dotted blue lines
sdarrup = meanarr + sdtemps
sdarrdown = meanarr - sdtemps
plt.plot(days,sdarrup,'--b')
plt.plot(days,sdarrdown,'--b')
plt.show()
import numpy as np
np.random.seed(12345)
x = np.random.randint ( low = 100, high = 200, size = 15)
print(x)
[198 129 101 136 141 134 129 101 159 114 191 180 173 111 177]
y = np.random.uniform(size = 15)
print (y)
[0.29150239 0.39874403 0.80728871 0.62709433 0.9079249 0.5563973
0.83991925 0.05048796 0.80623485 0.93081569 0.36402958 0.69094792
0.12931457 0.8326864 0.31835373]
z = np.random.uniform(size = 15)
z2 = 10 + (40-10)*z
print(z2)
[32.11606788 27.90308919 20.91120527 33.84911712 30.95443448 34.65636775
36.98397677 34.95697912 37.29873156 39.2474077 29.68358775 34.35968698
13.08231968 17.12585364 21.38035643]
norm = np.random.normal(size = 15)
print(norm)
[-0.14432722 1.9100403 1.80886729 -1.10594071 0.34453275 1.55301448
0.54780088 0.25643723 -1.51291728 -0.87810819 -0.01727617 -0.13659422
-0.73010902 1.39826774 -0.33692207]
norm2 = np.random.normal(size = 15)
norm2 = 20 + (0.5)*norm2
print(norm2)
[19.99765989 19.61988295 19.37694374 20.13942276 19.76339981 19.12893734
19.51595886 19.64518776 20.57745341 20.34537529 20.45634048 20.79604431
19.82228895 19.38476865 20.69735903]