numpy.random.randn(d0,d1,...,dn)
Return a sample (or samples) from the “standard normal” distribution.
根据传入参数,返回维度为(d0, d1, ..., dn)
的ndarray
的伪随机数,值的范围为标准正态分布。
Example code:
>>> import numpy as np
>>>
>>> array = np.random.randn(2,3)
>>> array
array([[1.63670217, 0.76860494, 1.4823955 ],
[1.51731369, 1.35266639, 0.32545556]])
>>> array = np.random.randn(3,3,2,4)
>>> array.shape
(3, 3, 2, 4)
numpy.random.normal(loc=0.0,scale=1.0,size=None)
Draw random samples from a normal (Gaussian) distribution.
Parameters | Type | Description |
---|---|---|
loc | float or array_like of floats | Mean (“centre”) of the distribution |
scale | float or array_like of floats | Standard deviation (spread or “width”) of the distribution. Must be non-negative |
size | int or tuple of ints, optional | Output shape. If the given shape is, e.g., (m, n, k) , then m * n * k samples are drawn. If size is None (default), a single value is returned if loc and scale are both scalars. Otherwise, np.broadcast(loc, scale).size samples are drawn |
根据参数调整正态分布的均值,宽度,以及返回的是几维的ndarray
只设置size
,loc
和scale
为默认,则数值范围为标准正态分布,与randn
类似。size
传入整数N,则生成长度N的一维ndarray
,传入元组,则根据元组创建相应维度的ndarray
Example code:
>>> array = np.random.normal(size=(2,3))
>>> array
array([[ 0.41314795, 0.08782946, 0.68626864],
[-2.10303548, 0.20703182, 0.93931345]])
>>> array = np.random.normal(10, 1, 1000)
>>> array.std()
1.0389318965769265
>>> array.mean()
10.074504683847726
>>> array.shape
(1000,)
>>> array = np.random.normal(10, 1, size=(3,3))
>>> array.mean()
10.106765370678746
>>> array.std()
0.7632711886498269
>>> array.shape
(3, 3)
numpy.random.Generator.lognormal(mean=0.0, sigma=1.0, size=None)
Draw samples from a log-normal distribution.
Draw samples from a log-normal distribution with specified mean, standard deviation, and array shape. Note that the mean and standard deviation are not the values for the distribution itself, but of the underlying normal distribution it is derived from.
Parameters | Type | Description |
---|---|---|
mean | float or array_like of floats, optional | Mean value of the underlying normal distribution. Default is 0 |
sigma | float or array_like of floats, optional | Standard deviation of the underlying normal distribution. Must be non-negative. Default is 1. |
size | int or tuple of ints, optional | Output shape. If the given shape is, e.g., (m, n, k) , then m * n * k samples are drawn. If size is None (default), a single value is returned if mean and sigma are both scalars. Otherwise, np.broadcast(mean, sigma).size samples are drawn |
lognormal
对数正态分布
与normal
类似,但一个为正态分布,一个为对数正态分布。