nlcpy.random.Generator.standard_normal

Generator.standard_normal(self, size=None, dtype='d', out=None)

Draws samples from a standard Normal distribution (mean=0, stdev=1).

Parameters
sizeint or tuple of ints, optional

Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn.

dtypestr or dtype, optional

Desired dtype of the result, either 'd' (or 'float64') or 'f' (or 'float32'). All dtypes are determined by their name. The default value is 'd'.

outndarray, optional

Alternative output array in which to place the result. If size is not None, it must have the same shape as the provided size and must match the type of the output values.

Returns
outndarray

A floating-point array of shape size of drawn samples, if size was not specified.

参考

Generator.normal

Draws random samples from a normal (Gaussian) distribution.

注釈

For random samples from N(\mu, \sigma^2), use one of:

mu + sigma * gen.standard_normal(size=...)
gen.normal(mu, sigma, size=...)

Examples

>>> import nlcpy as vp
>>> rng = vp.random.default_rng()
>>> rng.standard_normal()    
array(0.07802166) # random
>>> s = rng.standard_normal(8000)
>>> s  
array([-0.66533529, -0.26800564,  0.35053523, ..., -0.77485594,
       -0.31695012, -0.59517798])
>>> s.shape
(8000,)
>>> s = rng.standard_normal(size=(3, 4, 2))
>>> s.shape
(3, 4, 2)

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

>>> 3 + 2.5 * rng.standard_normal(size=(2, 4)) 
array([[2.85310426, 0.13495647, 0.04238584, 4.33929263],
       [3.61694001, 7.61121584, 2.65205908, 2.07678931]])