-
-
Save quantra-go-algo/f614cf95a2b7667aea5b04929c313137 to your computer and use it in GitHub Desktop.
How is Gaussian distribution calculated?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How is Gaussian distribution calculated? | |
# The example comes from the Numpy documentation at numpy.random.normal | |
# https://numpy.org/doc/stable/reference/random/generated/numpy.random.normal.html | |
import numpy as np | |
import matplotlib.pyplot as plt | |
# Draw samples from the distribution: | |
mu, sigma = 0, 0.1 # mean and standard deviation | |
s = np.random.normal(mu, sigma, 1000) | |
# Display the histogram of the samples, along with the probability density function: | |
# Plot the histogram | |
count, bins, ignored = plt.hist(s, 30, density=True) | |
# Plot the probability density function | |
plt.plot(bins, | |
1/(sigma * np.sqrt(2 * np.pi)) * np.exp( - (bins - mu)**2 / (2 * sigma**2) ), | |
linewidth=2, | |
color='r') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment