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
In terms of time consuming ,np.mean() Time will be longer than the second method . therefore , It is not recommended to use the mean value np modular .
When you look at the formula of variance, you know that you can't write without adding for loop , So here we recommend np modular
import numpy as np from time import time a = list(range(1, 100000)) s2 = np.var(a)
Direct use np.var() We can find the variance .
This is just a short square , You can also use np.std().