numpy.random.randn#
- random.randn(d0,d1,...,dn)#
Return a sample (or samples) from the “standard normal” distribution.
Note
This is a convenience function for users porting code from Matlab,and wraps
standard_normal. That function takes atuple to specify the size of the output, which is consistent withother NumPy functions likenumpy.zerosandnumpy.ones.Note
New code should use the
standard_normalmethod of aGeneratorinstance instead;please see theQuick start.If positive int_like arguments are provided,
randngenerates an arrayof shape(d0,d1,...,dn), filledwith random floats sampled from a univariate “normal” (Gaussian)distribution of mean 0 and variance 1. A single float randomly sampledfrom the distribution is returned if no argument is provided.- Parameters:
- d0, d1, …, dnint, optional
The dimensions of the returned array, must be non-negative.If no argument is given a single Python float is returned.
- Returns:
- Zndarray or float
A
(d0,d1,...,dn)-shaped array of floating-point samples fromthe standard normal distribution, or a single such float ifno parameters were supplied.
See also
standard_normalSimilar, but takes a tuple as its argument.
normalAlso accepts mu and sigma arguments.
random.Generator.standard_normalwhich should be used for new code.
Notes
For random samples from the normal distribution with mean
muandstandard deviationsigma, use:sigma*np.random.randn(...)+mu
Examples
>>>np.random.randn()2.1923875335537315 # random
Two-by-four array of samples from the normal distribution withmean 3 and standard deviation 2.5:
>>>3+2.5*np.random.randn(2,4)array([[-4.49401501, 4.00950034, -1.81814867, 7.29718677], # random [ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) # random