statistics.NormalDist.overlap(other)
The overlap method of an object of type statistics.NormalDist takes as an argument another distribution of the same type and returns a real value between 0.0 and 1.0 representing the overlapping area for both distributions.
- other: Distribution with which to compare the distribution to which the method is applied.
The statistics.NormalDist.overlap method returns a real number between 0.0 and 1.0.
If we start from the following two distributions:
dist2 = statistics.NormalDist(mu = 7, sigma = 1)
...we can generate a hundred thousand random samples for each one and display their histograms:
plt.hist(dist1.samples(100000), bins = 100, alpha = 0.6)
plt.hist(dist2.samples(100000), bins = 100, alpha = 0.6, color = "lightgreen")
plt.grid()
plt.show()
It can be seen visually that both distributions overlap. If we wanted to calculate the area covered by both distributions we could do it with the following code: