You are viewing an older version (2.4.3). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.4.3 / numpy / random / RandomState / randn

cython_function_or_method

numpy.random:RandomState.randn

Summary

Return a sample (or samples) from the "standard normal" distribution.

Extended Summary

If positive int_like arguments are provided, randn generates an array of shape (d0, d1, ..., dn), filled with random floats sampled from a univariate "normal" (Gaussian) distribution of mean 0 and variance 1. A single float randomly sampled from the distribution is returned if no argument is provided.

Parameters

d0, d1, ..., dn : int, optional

The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.

Returns

Z : ndarray or float

A (d0, d1, ..., dn)-shaped array of floating-point samples from the standard normal distribution, or a single such float if no parameters were supplied.

Notes

For random samples from the normal distribution with mean mu and standard deviation sigma, use

sigma * np.random.randn(...) + mu

Examples

np.random.randn()
Two-by-four array of samples from the normal distribution with mean 3 and standard deviation 2.5:
3 + 2.5 * np.random.randn(2, 4)

See also

normal

Also accepts mu and sigma arguments.

random.Generator.standard_normal

which should be used for new code.

standard_normal

Similar, but takes a tuple as its argument.

Aliases

  • numpy.random.randn
  • numpy.random.RandomState.randn