# 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]
avg = 0
variance = 0.0
n = len(temps)
# for plotting purposes I have added an array of days from 1 to 10
days = np.linspace(1,n,n)
for i in range (0,n):
avg = avg + temps [i]
mean = avg / float(n)
if (n % 2) == 0:
half = int (n/2)
median = (temps[half -1] + temps [half]) / 2
else:
half = int (n/2)
median = temps[half]
for j in range (0, n):
variance = variance +(temps[j] - mean)**2
variance = variance / float (n- 1)
print (f"Mean of temps is {stat.mean (temps)} ")
print (f"Median of temps is {stat.median (temps)} ")
print (f"Mode of temps is{ stat.mode (temps)}")
print (f"Variance of sample temps is {variance}")
print (f"Standard deviation of temps is {stat.stdev (temps)}")
# Plot the temperatures vs the days as a scatter plot using a red "x"
t = temps
d = days
plt.plot (d, t, 'rx')
plt.show ( )
#
# Plot the mean as a horizontal line in green
x = np.linspace(mean, mean)
plt.plot (x,'g')
plt.show ( )
#
# Illustrate 1 standard deviation away from the mean by drawing two horizonal lines in
# as dotted blue lines
sd = stat.stdev(temps)
y = np.linspace(sd , sd)
plt.plot(y- 1, '-b')
plt.show()
import numpy as np
np.random.seed(12345)
x = np.random.randint (low = 100, high = 200, size = 15)
print (x)
x = np.random.uniform (size = 15)
print (x)
xp = np.random.uniform (size = 15)
x = 15 + (40-10)*x
print (x)
x = np.random.normal(size = 15)
print (x)
x = np.random.normal(size = 15)
x = 20 + (.5)*x
print (x)