numpy.random.normal — NumPy v1.18.dev0 Manual (2024)

Draw random samples from a normal (Gaussian) distribution.

The probability density function of the normal distribution, firstderived by De Moivre and 200 years later by both Gauss and Laplaceindependently [2], is often called the bell curve because ofits characteristic shape (see the example below).

The normal distributions occurs often in nature. For example, itdescribes the commonly occurring distribution of samples influencedby a large number of tiny, random disturbances, each with its ownunique distribution [2].

Note

New code should use the normal method of a default_rng()instance instead; see random-quick-start.

Parameters
locfloat or array_like of floats

Mean (“centre”) of the distribution.

scalefloat or array_like of floats

Standard deviation (spread or “width”) of the distribution. Must benon-negative.

sizeint or tuple of ints, optional

Output shape. If the given shape is, e.g., (m, n, k), thenm * n * k samples are drawn. If size is None (default),a single value is returned if loc and scale are both scalars.Otherwise, np.broadcast(loc, scale).size samples are drawn.

Returns
outndarray or scalar

Drawn samples from the parameterized normal distribution.

Notes

The probability density for the Gaussian distribution is

System Message: WARNING/2 (p(x) = \frac{1}{\sqrt{ 2 \pi \sigma^2 }}e^{ - \frac{ (x - \mu)^2 } {2 \sigma^2} },)

latex exited with error[stdout]This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian) (preloaded format=latex) restricted \write18 enabled.entering extended mode(./math.texLaTeX2e <2017-04-15>Babel <3.18> and hyphenation patterns for 3 language(s) loaded.(/usr/share/texlive/texmf-dist/tex/latex/base/article.clsDocument Class: article 2014/09/29 v1.4h Standard LaTeX document class(/usr/share/texlive/texmf-dist/tex/latex/base/size12.clo))(/usr/share/texlive/texmf-dist/tex/latex/base/inputenc.sty(/usr/share/texlive/texmf-dist/tex/latex/base/utf8.def(/usr/share/texlive/texmf-dist/tex/latex/base/t1enc.dfu)(/usr/share/texlive/texmf-dist/tex/latex/base/ot1enc.dfu)(/usr/share/texlive/texmf-dist/tex/latex/base/omsenc.dfu)))(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.styFor additional information on amsmath, use the `?' option.(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amstext.sty(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty))(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsbsy.sty)(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsopn.sty))(/usr/share/texlive/texmf-dist/tex/latex/amscls/amsthm.sty)(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty))! LaTeX Error: File `anyfontsize.sty' not found.Type X to quit or <RETURN> to proceed,or enter new name. (Default extension: sty)Enter file name: ! Emergency stop.<read *> l.8 \usepackage {bm}^^MNo pages of output.Transcript written on math.log.

where

System Message: WARNING/2 (\mu)

latex exited with error[stdout]This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian) (preloaded format=latex) restricted \write18 enabled.entering extended mode(./math.texLaTeX2e <2017-04-15>Babel <3.18> and hyphenation patterns for 3 language(s) loaded.(/usr/share/texlive/texmf-dist/tex/latex/base/article.clsDocument Class: article 2014/09/29 v1.4h Standard LaTeX document class(/usr/share/texlive/texmf-dist/tex/latex/base/size12.clo))(/usr/share/texlive/texmf-dist/tex/latex/base/inputenc.sty(/usr/share/texlive/texmf-dist/tex/latex/base/utf8.def(/usr/share/texlive/texmf-dist/tex/latex/base/t1enc.dfu)(/usr/share/texlive/texmf-dist/tex/latex/base/ot1enc.dfu)(/usr/share/texlive/texmf-dist/tex/latex/base/omsenc.dfu)))(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.styFor additional information on amsmath, use the `?' option.(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amstext.sty(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty))(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsbsy.sty)(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsopn.sty))(/usr/share/texlive/texmf-dist/tex/latex/amscls/amsthm.sty)(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty))! LaTeX Error: File `anyfontsize.sty' not found.Type X to quit or <RETURN> to proceed,or enter new name. (Default extension: sty)Enter file name: ! Emergency stop.<read *> l.8 \usepackage {bm}^^MNo pages of output.Transcript written on math.log.

is the mean and

System Message: WARNING/2 (\sigma)

latex exited with error[stdout]This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian) (preloaded format=latex) restricted \write18 enabled.entering extended mode(./math.texLaTeX2e <2017-04-15>Babel <3.18> and hyphenation patterns for 3 language(s) loaded.(/usr/share/texlive/texmf-dist/tex/latex/base/article.clsDocument Class: article 2014/09/29 v1.4h Standard LaTeX document class(/usr/share/texlive/texmf-dist/tex/latex/base/size12.clo))(/usr/share/texlive/texmf-dist/tex/latex/base/inputenc.sty(/usr/share/texlive/texmf-dist/tex/latex/base/utf8.def(/usr/share/texlive/texmf-dist/tex/latex/base/t1enc.dfu)(/usr/share/texlive/texmf-dist/tex/latex/base/ot1enc.dfu)(/usr/share/texlive/texmf-dist/tex/latex/base/omsenc.dfu)))(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.styFor additional information on amsmath, use the `?' option.(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amstext.sty(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty))(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsbsy.sty)(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsopn.sty))(/usr/share/texlive/texmf-dist/tex/latex/amscls/amsthm.sty)(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty))! LaTeX Error: File `anyfontsize.sty' not found.Type X to quit or <RETURN> to proceed,or enter new name. (Default extension: sty)Enter file name: ! Emergency stop.<read *> l.8 \usepackage {bm}^^MNo pages of output.Transcript written on math.log.

the standarddeviation. The square of the standard deviation,

System Message: WARNING/2 (\sigma^2)

latex exited with error[stdout]This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian) (preloaded format=latex) restricted \write18 enabled.entering extended mode(./math.texLaTeX2e <2017-04-15>Babel <3.18> and hyphenation patterns for 3 language(s) loaded.(/usr/share/texlive/texmf-dist/tex/latex/base/article.clsDocument Class: article 2014/09/29 v1.4h Standard LaTeX document class(/usr/share/texlive/texmf-dist/tex/latex/base/size12.clo))(/usr/share/texlive/texmf-dist/tex/latex/base/inputenc.sty(/usr/share/texlive/texmf-dist/tex/latex/base/utf8.def(/usr/share/texlive/texmf-dist/tex/latex/base/t1enc.dfu)(/usr/share/texlive/texmf-dist/tex/latex/base/ot1enc.dfu)(/usr/share/texlive/texmf-dist/tex/latex/base/omsenc.dfu)))(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.styFor additional information on amsmath, use the `?' option.(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amstext.sty(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty))(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsbsy.sty)(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsopn.sty))(/usr/share/texlive/texmf-dist/tex/latex/amscls/amsthm.sty)(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty))! LaTeX Error: File `anyfontsize.sty' not found.Type X to quit or <RETURN> to proceed,or enter new name. (Default extension: sty)Enter file name: ! Emergency stop.<read *> l.8 \usepackage {bm}^^MNo pages of output.Transcript written on math.log.

,is called the variance.

The function has its peak at the mean, and its “spread” increases withthe standard deviation (the function reaches 0.607 times its maximum at

System Message: WARNING/2 (x + \sigma)

latex exited with error[stdout]This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian) (preloaded format=latex) restricted \write18 enabled.entering extended mode(./math.texLaTeX2e <2017-04-15>Babel <3.18> and hyphenation patterns for 3 language(s) loaded.(/usr/share/texlive/texmf-dist/tex/latex/base/article.clsDocument Class: article 2014/09/29 v1.4h Standard LaTeX document class(/usr/share/texlive/texmf-dist/tex/latex/base/size12.clo))(/usr/share/texlive/texmf-dist/tex/latex/base/inputenc.sty(/usr/share/texlive/texmf-dist/tex/latex/base/utf8.def(/usr/share/texlive/texmf-dist/tex/latex/base/t1enc.dfu)(/usr/share/texlive/texmf-dist/tex/latex/base/ot1enc.dfu)(/usr/share/texlive/texmf-dist/tex/latex/base/omsenc.dfu)))(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.styFor additional information on amsmath, use the `?' option.(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amstext.sty(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty))(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsbsy.sty)(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsopn.sty))(/usr/share/texlive/texmf-dist/tex/latex/amscls/amsthm.sty)(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty))! LaTeX Error: File `anyfontsize.sty' not found.Type X to quit or <RETURN> to proceed,or enter new name. (Default extension: sty)Enter file name: ! Emergency stop.<read *> l.8 \usepackage {bm}^^MNo pages of output.Transcript written on math.log.

and

System Message: WARNING/2 (x - \sigma)

latex exited with error[stdout]This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian) (preloaded format=latex) restricted \write18 enabled.entering extended mode(./math.texLaTeX2e <2017-04-15>Babel <3.18> and hyphenation patterns for 3 language(s) loaded.(/usr/share/texlive/texmf-dist/tex/latex/base/article.clsDocument Class: article 2014/09/29 v1.4h Standard LaTeX document class(/usr/share/texlive/texmf-dist/tex/latex/base/size12.clo))(/usr/share/texlive/texmf-dist/tex/latex/base/inputenc.sty(/usr/share/texlive/texmf-dist/tex/latex/base/utf8.def(/usr/share/texlive/texmf-dist/tex/latex/base/t1enc.dfu)(/usr/share/texlive/texmf-dist/tex/latex/base/ot1enc.dfu)(/usr/share/texlive/texmf-dist/tex/latex/base/omsenc.dfu)))(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.styFor additional information on amsmath, use the `?' option.(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amstext.sty(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty))(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsbsy.sty)(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsopn.sty))(/usr/share/texlive/texmf-dist/tex/latex/amscls/amsthm.sty)(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty))! LaTeX Error: File `anyfontsize.sty' not found.Type X to quit or <RETURN> to proceed,or enter new name. (Default extension: sty)Enter file name: ! Emergency stop.<read *> l.8 \usepackage {bm}^^MNo pages of output.Transcript written on math.log.

[2]). This implies thatnormal is more likely to return samples lying close to the mean, ratherthan those far away.

References

1

Wikipedia, “Normal distribution”,https://en.wikipedia.org/wiki/Normal_distribution

2(1,2,3)

P. R. Peebles Jr., “Central Limit Theorem” in “Probability,Random Variables and Random Signal Principles”, 4th ed., 2001,pp. 51, 51, 125.

Examples

Draw samples from the distribution:

>>> mu, sigma = 0, 0.1 # mean and standard deviation>>> s = np.random.normal(mu, sigma, 1000)

Verify the mean and the variance:

>>> abs(mu - np.mean(s))0.0 # may vary
>>> abs(sigma - np.std(s, ddof=1))0.1 # may vary

Display the histogram of the samples, along withthe probability density function:

>>> import matplotlib.pyplot as plt>>> count, bins, ignored = plt.hist(s, 30, density=True)>>> plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) *...  np.exp( - (bins - mu)**2 / (2 * sigma**2) ),...  linewidth=2, color='r')>>> plt.show()

numpy.random.normal — NumPy v1.18.dev0 Manual (1)

Two-by-four array of samples from N(3, 6.25):

>>> np.random.normal(3, 2.5, size=(2, 4))array([[-4.49401501, 4.00950034, -1.81814867, 7.29718677], # random [ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) # random
numpy.random.normal — NumPy v1.18.dev0 Manual (2024)

References

Top Articles
Latest Posts
Article information

Author: Velia Krajcik

Last Updated:

Views: 5933

Rating: 4.3 / 5 (54 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Velia Krajcik

Birthday: 1996-07-27

Address: 520 Balistreri Mount, South Armand, OR 60528

Phone: +466880739437

Job: Future Retail Associate

Hobby: Polo, Scouting, Worldbuilding, Cosplaying, Photography, Rowing, Nordic skating

Introduction: My name is Velia Krajcik, I am a handsome, clean, lucky, gleaming, magnificent, proud, glorious person who loves writing and wants to share my knowledge and understanding with you.