函数: numpy.random.uniform(low,high,size)
Draw samples from a uniform distribution.
Samples are uniformly distributed over the half-open interval
----------
low : float or array_like of floats, optional
Lower boundary of the output interval. All values generated will be
greater than or equal to low. The default value is 0.
high : float or array_like of floats
Upper boundary of the output interval. All values generated will be
less than or equal to high. The default value is 1.0.
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 ``low`` and ``high`` are both scalars.
Otherwise, ``np.broadcast(low, high).size`` samples are drawn.
Returns
-------
功能:从一个均匀分布[low,high)中随机采样,采样数量为size。注意定义域是左闭右开,即包含low,不包含high。
参数介绍:
(1) low: 采样下界,float类型,默认值为0。
(2) high: 采样上界,float类型,默认值为1。
(3) size: 输出样本数目,为int或元组(tuple)类型,例如,size=(m,n,k), 则输出m n k个样本。缺省时输出1个值。
(4) 返回值:numpy ndarray类型,其形状和参数size中描述一致。
举例:
import numpy as np
a = np.random.uniform()
b = np.random.uniform(1, 3, 5)
c = np.random.uniform(7, 10, (2, 3))
print(
'a=', a,
'\nb=', b,
'\nc=', c,
)
得到输出:
a= 0.37237035830791587
b= [1.99963941 1.27452227 2.54252202 2.68460081 1.04137335]
c= [[7.81326369 8.62565301 8.48519219]
[9.27817572 8.47892165 9.83586147]]