Loi normale centrée réduite
Générer des nombres aléatoires depuis une loi normale centrée réduite (ou loi normale standard) en python:

import numpy as npimport matplotlib.pyplot as pltdata = np.random.randn(100000)hx, hy, _ = plt.hist(data, bins=50, normed=1,color="lightblue")plt.ylim(0.0,max(hx)+0.05)plt.title('Generate random numbers \n from a standard normal distribution with python')plt.grid()plt.savefig("numpy_random_numbers_stantard_normal_distribution.png", bbox_inches='tight')plt.show()
Loi normale
Si on sait comment générer des nombres aléatoires depuis une loi normale centrée réduite, on peut alors facilement générer des nombres aléatoires depuis une loi normale quelconque avec la formule $$X = Z * \sigma + \mu$$
ou Z est un nombres aléatoire généré depuis une loi normale centrée réduite, $\sigma$ la standard deviation et $\mu$ la moyenne.

import numpy as npimport matplotlib.pyplot as pltmu = 10.0sigma = 2.0data = np.random.randn(100000) * sigma + muhx, hy, _ = plt.hist(data, bins=50, normed=1,color="lightblue")plt.ylim(0.0,max(hx)+0.05)plt.title('Generate random numbers \n from a normal distribution with python')plt.grid()plt.savefig("numpy_random_numbers_normal_distribution.png", bbox_inches='tight')plt.show()
Références
| Liens | Site |
|---|---|
| Normal distribution | wikipedia |
| numpy.random.randn | doc scipy |
| numpy.random.normal | doc scipy |
