 # Summary Statistics Using Numpy

Last updated: October 31st, 2019  # Summary statistics using NumPy¶

In descriptive statistics, summary statistics are used to summarize a set of observations, in order to communicate the largest amount of information as simply as possible. Statisticians commonly try to describe the observations in

• a measure of location, or central tendency, such as the arithmetic mean.
• a measure of statistical dispersion like the standard deviation.
• a measure of the shape of the distribution like skewness or kurtosis.
• if more than one variable is measured, a measure of statistical dependence such as a correlation coefficient.

NumPy has quite a few useful statistical functions for calculating sum, mean, standard deviation and variance, etc. from the given elements in the array. ## Hands on!¶

In :
import sys
import numpy as np


### Summary statistics¶

In :
a = np.array([1, 2, 3, 4])

In :
a.shape

Out:
(4,)
In :
a.sum()

Out:
10
In :
a.mean()

Out:
2.5
In :
a.std()

Out:
1.118033988749895
In :
a.var()

Out:
1.25
In :
A = np.array([
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
])

In :
A.sum()

Out:
45
In :
A.mean()

Out:
5.0
In :
A.std()

Out:
2.581988897471611
In :
A.sum(axis=0)

Out:
array([12, 15, 18])
In :
A.sum(axis=1)

Out:
array([ 6, 15, 24])
In :
A.mean(axis=0)

Out:
array([4., 5., 6.])
In :
A.mean(axis=1)

Out:
array([2., 5., 8.])
In :
A.std(axis=0)

Out:
array([2.44948974, 2.44948974, 2.44948974])
In :
A.std(axis=1)

Out:
array([0.81649658, 0.81649658, 0.81649658])

#### Cumulative sum of elements starting from 0¶

In :
A

Out:
array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
In :
A.cumsum()

Out:
array([ 1,  3,  6, 10, 15, 21, 28, 36, 45])

#### Cumulative product of elements starting from 1¶

In :
A.cumprod()

Out:
array([     1,      2,      6,     24,    120,    720,   5040,  40320,
362880])

#### And many more...¶ 