randn#
- class brainstate.random.randn(*dn, key=None, dtype=None)#
Return a sample (or samples) from the “standard normal” distribution.
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 (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.
d1 (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.
... (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.
dn (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.
key (
int|Array|ndarray|None) – The key for the random number generator. If not given, the default random number generator is used.
- Returns:
Z – 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.- Return type:
ndarray or float
See also
standard_normalSimilar, but takes a tuple as its argument.
normalAlso accepts mu and sigma arguments.
Notes
For random samples from \(N(\mu, \sigma^2)\), use:
sigma * brainstate.random.randn(...) + muExamples
Generate a single random number from standard normal distribution:
>>> import brainstate >>> val = brainstate.random.randn() >>> print(type(val)) # <class 'numpy.float64'>
Generate a 2x4 array of standard normal samples:
>>> arr = brainstate.random.randn(2, 4) >>> print(arr.shape) # (2, 4)
Two-by-four array of samples from N(3, 6.25):
>>> arr = 3 + 2.5 * brainstate.random.randn(2, 4) >>> print(arr.shape) # (2, 4)