To integrate a simple normal distribution in python, a solution is to use quad, example:

from scipy.integrate import quadimport matplotlib.pyplot as pltimport scipy.statsimport numpy as np#----------------------------------------------------------------------------------------## Normal Distributionx_min = 0.0x_max = 16.0mean = 8.0std = 3.0x = np.linspace(x_min, x_max, 100)y = scipy.stats.norm.pdf(x,mean,std)plt.plot(x,y, color='black')#----------------------------------------------------------------------------------------## integration between x1 and x1def normal_distribution_function(x):value = scipy.stats.norm.pdf(x,mean,std)return valuex1 = mean + stdx2 = mean + 2.0 * stdres, err = quad(normal_distribution_function, x1, x2)print('Normal Distribution (mean,std):',mean,std)print('Integration bewteen {} and {} --> '.format(x1,x2),res)#----------------------------------------------------------------------------------------## plot integration surfaceptx = np.linspace(x1, x2, 10)pty = scipy.stats.norm.pdf(ptx,mean,std)plt.fill_between(ptx, pty, color='#0b559f', alpha='1.0')#----------------------------------------------------------------------------------------#plt.grid()plt.xlim(x_min,x_max)plt.ylim(0,0.25)plt.title('How to integrate a normal distribution in python ?',fontsize=10)plt.xlabel('x')plt.ylabel('Normal Distribution')plt.savefig("integrate_normal_distribution.png")plt.show()
with a mean and standard deviation (std) of 8.0 and 3.0 respectively, the integration between 1 * std and 2 * std
returns:
>>> Normal Distribution (mean,std): 8.0 3.0>>> Integration bewteen 11.0 and 14.0 --> 0.13590512198327787
It is possible to integrate a function that takes several parameters with quad in python, example of syntax for a function f that takes two arguments: arg1 and arg2:
quad( f, x_min, x_max, args=(arg1,arg2,))
Example of code using quad with a function that takes multiple arguments:

from scipy.integrate import quadimport matplotlib.pyplot as pltimport scipy.statsimport numpy as npdef normal_distribution_function(x,mean,std):value = scipy.stats.norm.pdf(x,mean,std)return valuex_min = 0.0x_max = 30.0mean = 15.0std = 4.0ptx = np.linspace(x_min, x_max, 100)pty = scipy.stats.norm.pdf(ptx,mean,std)plt.plot(ptx,pty, color='gray')plt.fill_between(ptx, pty, color='#e1b1b4', alpha='1.0')plt.grid()plt.title('How to integrate a function that takes parameteres in python ?', fontsize=10)plt.xlabel('x', fontsize=8)plt.ylabel('Probability Density Function', fontsize=8)res, err = quad(normal_distribution_function, x_min, x_max, args=(mean,std,))print(res)plt.savefig("integrate_function_takes_parameters.png")plt.show()
References
| Links | Site |
|---|---|
| Best way to write a Python function that integrates a gaussian? | stackoverflow |
| quad | ocs.scipy.org |
| Integration using the quad method python | stackoverflow |
| SciPy - Integrate | tutorialspoint |
| How to evaluate single integrals of multivariate functions with Python's scipy.integrate.quad? | stackoverflow |
| quad | doc scipy |
