Randn、normal&lognormal

numpy.random.randn(d0,d1,...,dn)

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

根據(jù)傳入?yún)?shù),返回維度為(d0, d1, ..., dn)ndarray的偽隨機數(shù),值的范圍為標準正態(tài)分布。

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

根據(jù)參數(shù)調(diào)整正態(tài)分布的均值,寬度,以及返回的是幾維的ndarray

只設(shè)置sizelocscale為默認,則數(shù)值范圍為標準正態(tài)分布,與randn類似。size傳入整數(shù)N,則生成長度N的一維ndarray,傳入元組,則根據(jù)元組創(chuàng)建相應(yīng)維度的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 對數(shù)正態(tài)分布

normal類似,但一個為正態(tài)分布,一個為對數(shù)正態(tài)分布。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容