Statistical Functions

Table of Contents

Statistical Functions

Numpy has many useful statistical functions for calculating mean, minimum across any axis, variances etc.
1.) Order Statistics
  a.) Numpy.amin(): Returns the minimum across any axis.
  b.) Numpy.amax(): Returns the maximum across any axis.
  c.) Numpy.percentile(): Returns the qth percentile of the data along the specified axis. This function is the same as the median if q=50, the same as the minimum if q=0 and the same as the maximum if q=100.
Order Statistics
2.) Average and Variances
  a.) Numpy.median(): Compute the median along the specified axis.
  b.) Numpy.var(): Compute the variance along the specified axis. Directly, using the function we can calculate it as:
Numpy.var(x, axis=0) : It is calculating variance across columns.
Numpy.var(x, axis=1) : It is calculating variance across rows.
Numpy.var(x): It is calculating variance taking as the whole array.
If you want to know the core details of calculation behind variance go through this:
Variance is calculated as, suppose we are having the no. of data points X1, X2,. . . . , Xn then the variance is calculated (this is not including across any axis, it is simply for whole Numpy array. In order to calculate along any axis we need to modify our process a bit.) as:
Step 1: Calculate the mean of all data points. Using Numpy you can do it as->y=x.mean()
Step 2: Subtract the mean from each data point Xi and squaring them.Using Numpy->z=np.sum(np.square(x-y))
Step 3: In the final step, sum up all the squared results and then divide by no. of data points.Using Numpy->z/x.size

Average and Variances

1. np.median() -> Calculates the median of an array.For median, if no. of values are even then it takes an average of middle elements.
For median, if no. of values is odd then it takes simply the middle element

2. numpy.var() -> Calculates the variance of matrix

This is for matrix along axis=1

Close Menu