Skip to content

Instantly share code, notes, and snippets.

@quantra-go-algo
Created January 12, 2022 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quantra-go-algo/f614cf95a2b7667aea5b04929c313137 to your computer and use it in GitHub Desktop.
Save quantra-go-algo/f614cf95a2b7667aea5b04929c313137 to your computer and use it in GitHub Desktop.
How is Gaussian distribution calculated?
# 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