Mean

The mean or average when the context is clear, is the sum of a collection of numbers divided by the number of numbers in the collection. A=(a1+a2+...+an)\n

In [51]:
import numpy as np
sal=np.array([22,24,27,31,31,31,32,32,32,32,44,45,48,53,55,60,70,80,80,110,150,300]) #create list of workers income
sal
Out[51]:
array([ 22,  24,  27,  31,  31,  31,  32,  32,  32,  32,  44,  45,  48,
        53,  55,  60,  70,  80,  80, 110, 150, 300])
In [52]:
l=0 #sum of a elements of array
n=0 #number of elements in array
m=0 #mean
for i in sal:
    l=l+i
    n=n+1
m=l/n
print(' sum of all elements of array:',l,'\n number of elements in array:',n,'\n mean:',m)
 sum of all elements of array: 1389 
 number of elements in array: 22 
 mean: 63.1363636364
In [53]:
l=sal.sum()
n=sal.size
m=l/n
print(' sum of all elements of array:',l,'\n number of elements in array:',n,'\n mean:',m)
 sum of all elements of array: 1389 
 number of elements in array: 22 
 mean: 63.1363636364
In [54]:
np.mean(sal)
Out[54]:
63.136363636363633
In [58]:
%matplotlib inline
import matplotlib.pyplot as plt
plt.hist(sal )
plt.show()