In [1]:
import matplotlib
from datascience import *
%matplotlib inline
import matplotlib.pyplot as plots
import numpy as np
plots.style.use('fivethirtyeight')

Lecture 25¶

Average (Mean)¶

There are many ways to compute the mean (average).

In [2]:
values = make_array(2, 3, 3, 9)
values
Out[2]:
array([2, 3, 3, 9])
In [3]:
sum(values)/len(values)
Out[3]:
4.25
In [4]:
np.average(values)
Out[4]:
4.25
In [5]:
np.mean(values)
Out[5]:
4.25
In [6]:
(2 + 3 + 3 + 9)/4
Out[6]:
4.25

Can also be framed as a weighted average of the unique values.

In [7]:
2*(1/4) + 3*(2/4) + 9*(1/4)
Out[7]:
4.25
In [8]:
2*0.25 + 3*0.5 + 9*0.25
Out[8]:
4.25
In [9]:
values_table = Table().with_columns('value', values)
values_table
Out[9]:
value
2
3
3
9
In [10]:
bins_for_display = np.arange(0.5, 10.6, 1)
values_table.ihist('value', bins = bins_for_display)