python-scipyHow do I use Python and SciPy to generate a Gaussian distribution?
The SciPy library provides a number of functions for generating a Gaussian distribution. To use Python and SciPy to generate a Gaussian distribution, the following steps need to be taken:
- Import the SciPy library:
import scipy.stats as stats
- Generate the Gaussian distribution using the
stats.norm()
function. The function takes three parameters: mean, standard deviation and size. For example, to generate a Gaussian distribution with mean 0 and standard deviation 1, use:
x = stats.norm(0, 1).rvs(1000)
- Plot the Gaussian distribution using the
matplotlib
library.import matplotlib.pyplot as plt
plt.hist(x, bins=30, density=True) plt.show()
The output will be a histogram of the generated Gaussian distribution:
![Gaussian Distribution](https://upload.wikimedia.org/wikipedia/commons/thumb/7/74/Normal_Distribution_PDF.svg/400px-Normal_Distribution_PDF.svg.png)
## Helpful links
- [SciPy Documentation](https://docs.scipy.org/doc/scipy/reference/index.html)
- [Matplotlib Documentation](https://matplotlib.org/3.2.1/contents.html)
More of Python Scipy
- How do I create a 2D array of zeros using Python and NumPy?
- How can I use Python and SciPy to find the zeros of a function?
- How do I create a numpy array of zeros using Python?
- How do I use the trapz function in Python SciPy?
- How do I convert a Python numpy.ndarray to a list?
- How do I use Python Scipy to perform a Z test?
- How can I use Python and Numpy to parse XML data?
- How do I create a numpy array of zeros using Python?
- How do I use the scipy ttest_ind function in Python?
- How do I calculate a Jacobian matrix using Python and NumPy?
See more codes...