# Numerical arrays.
import numpy as np
# Plotting.
import matplotlib.pyplot as plt
# Change plot style.
plt.style.use('fivethirtyeight')
# Change default figure size.
plt.rcParams['figure.figsize'] = [12, 8]
mu, sigma = 0, 0.1 # mean and standard deviation
s = np.random.default_rng().normal(mu, sigma, 1000)
s[:10]
array([ 0.05096108, 0.06106065, -0.18797417, 0.07885399, -0.02960684, -0.0775354 , 0.16937639, 0.140479 , 0.09634012, -0.00776155])
abs(mu - np.mean(s))
0.0026846616194203463
abs(sigma - np.std(s, ddof=1))
0.002022387933364428
count, bins, ignored = plt.hist(s, 30, density=True)
f = 1/(sigma * np.sqrt(2 * np.pi)) * np.exp( - (bins - mu)**2 / (2 * sigma**2) )
plt.plot(bins, f, linewidth=2)
plt.show()