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è)置size,loc和scale為默認,則數(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)分布。