Movatterモバイル変換


[0]ホーム

URL:


SciPy

numpy.random.normal

numpy.random.normal(loc=0.0,scale=1.0,size=None)

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[R255], 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[R255].

Parameters:

loc : float or array_like of floats

Mean (“centre”) of the distribution.

scale : float or array_like of floats

Standard deviation (spread or “width”) of the distribution.

size : int 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 isNone (default),a single value is returned ifloc andscale are both scalars.Otherwise,np.broadcast(loc,scale).size samples are drawn.

Returns:

out : ndarray or scalar

Drawn samples from the parameterized normal distribution.

See also

scipy.stats.norm
probability density function, distribution or cumulative density function, etc.

Notes

The probability density for the Gaussian distribution is

p(x) = \frac{1}{\sqrt{ 2 \pi \sigma^2 }}e^{ - \frac{ (x - \mu)^2 } {2 \sigma^2} },

where\mu is the mean and\sigma the standarddeviation. The square of the standard deviation,\sigma^2,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 atx + \sigma andx - \sigma[R255]). This implies thatnumpy.random.normal is more likely to return samples lying close tothe mean, rather than those far away.

References

[R254]Wikipedia, “Normal distribution”,http://en.wikipedia.org/wiki/Normal_distribution
[R255](1,2,3,4) 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.01True
>>>abs(sigma-np.std(s,ddof=1))<0.01True

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

>>>importmatplotlib.pyplotasplt>>>count,bins,ignored=plt.hist(s,30,normed=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()

(Source code,png,pdf)

../../_images/numpy-random-normal-1.png

Previous topic

numpy.random.noncentral_f

Next topic

numpy.random.pareto

  • © Copyright 2008-2009, The Scipy community.
  • Last updated on Jun 10, 2017.
  • Created usingSphinx 1.5.3.

[8]ページ先頭

©2009-2025 Movatter.jp