Computing the average, standard deviation, and higher moments of a distribution
In order to understand the way in which we can extract the average of a distribution, let us go through the following scenario.
How to do it...
We will initialize a normal distribution with a given average and standard deviation. Once initialized, we will consider the output that we should be expecting.
Initializing a normal distribution
A normal variable with a given mean and standard deviation can be initialized by using the rvs
function in scipy.stats.norm
:
- Import the relevant packages:
from scipy import stats
- Initialize a variable with a given mean and standard distribution:
x = stats.norm.rvs(loc=3, scale=2, size=(1000))
In the preceding line of code, we have initialized a variable x, which has a mean value of 3, a standard deviation of 2, and a total size of 1,000.
Note that the mean is referred to as loc
and the standard deviation as scale
in the line of code.
- Now, we have obtained the values of
x
, let's go ahead...