standard_normal#
- class brainstate.random.standard_normal(size=None, key=None, dtype=None)#
Draw samples from a standard Normal distribution (mean=0, stdev=1).
- Parameters:
size (
int|Sequence[int] |integer|Sequence[integer] |None) – Output shape. If the given shape is, e.g.,(m, n, k), thenm * n * ksamples are drawn. Default is None, in which case a single value 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:
out – A floating-point array of shape
sizeof drawn samples, or a single sample ifsizewas not specified.- Return type:
float or ndarray
See also
normalEquivalent function with additional
locandscalearguments for setting the mean and standard deviation.
Notes
For random samples from the normal distribution with mean
muand standard deviationsigma, use one of:mu + sigma * brainstate.random.standard_normal(size=...) brainstate.random.normal(mu, sigma, size=...)
Examples
Generate a single standard normal sample:
>>> import brainstate >>> val = brainstate.random.standard_normal() >>> print(type(val)) # <class 'numpy.float64'>
Generate an array of 8000 standard normal samples:
>>> s = brainstate.random.standard_normal(8000) >>> print(s.shape) # (8000,)
Generate a 3x4x2 array of standard normal samples:
>>> s = brainstate.random.standard_normal(size=(3, 4, 2)) >>> print(s.shape) # (3, 4, 2)
Two-by-four array of samples from the normal distribution with mean 3 and standard deviation 2.5:
>>> samples = 3 + 2.5 * brainstate.random.standard_normal(size=(2, 4)) print(samples.shape) # (2, 4)