1. Find the mean:
import numpy as np
from time import time
a = list(range(1, 100000))
mean1 = np.mean(a) # method 1
mean2 = sum(a) / len(a) # method 2
From the time-consuming point of view, np.mean() will take longer than the second method . Therefore, it is not recommended to use the np module for averaging .
2. Find the variance:
When you look at the formula of variance, you know that you have to add a for loop to write it, so the np module is recommended here
import numpy as np
from time import time
a = list(range(1, 100000))
s2 = np.var(a)
You can find the variance directly with np.var() .
3. Find the difference:
This can be done directly, and np.std() can also be used .