In [1]:
import statistics
import math
In [2]:
l = [10, 1, 3, 7, 1]
In [3]:
mean = statistics.mean(l)
print(mean)
In [4]:
my_mean = sum(l) / len(l)
print(my_mean)
In [5]:
harmonic_mean = statistics.harmonic_mean(l)
print(harmonic_mean)
In [6]:
my_harmonic_mean = len(l) / sum(1 / x for x in l)
print(my_harmonic_mean)
In [7]:
median = statistics.median(l)
print(median)
In [8]:
l_even = [10, 1, 3, 7, 1, 6]
In [9]:
median = statistics.median(l_even)
print(median)
In [10]:
median_low = statistics.median_low(l_even)
print(median_low)
In [11]:
median_high = statistics.median_high(l_even)
print(median_high)
In [12]:
print(statistics.median_high(l) == statistics.median_low(l) == statistics.median(l))
In [13]:
mode = statistics.mode(l)
print(mode)
In [14]:
l_mode_error = [1, 2, 3, 4, 5]
# mode = statistics.mode(l_mode_error)
# StatisticsError: no unique mode; found 5 equally common values
In [15]:
l_mode_error = [1, 1, 1, 2, 2, 2, 3]
# mode = statistics.mode(l_mode_error)
# StatisticsError: no unique mode; found 2 equally common values
In [16]:
pvariance = statistics.pvariance(l)
print(pvariance)
In [17]:
my_pvariance = sum((x - sum(l) / len(l))**2 for x in l) / len(l)
print(my_pvariance)
In [18]:
pstdev = statistics.pstdev(l)
print(pstdev)
In [19]:
print(math.sqrt(pvariance))
In [20]:
variance = statistics.variance(l)
print(variance)
In [21]:
my_variance = sum((x - sum(l) / len(l))**2 for x in l) / (len(l) - 1)
print(my_variance)
In [22]:
stdev = statistics.stdev(l)
print(stdev)
In [23]:
print(math.sqrt(variance))