函数: numpy.random.uniform(low,high,size)
功能:从一个均匀分布[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(2, 3, 3)
c = np.random.uniform(9, 10, (2, 3))
print(
'a=', a,
'\nb=', b,
'\nc=', c,
)
得到输出:
a= 0.6416026226167829
b= [2.8868665 2.23328114 2.11853355]
c= [[9.92113472 9.21390707 9.24170646]
[9.80620397 9.39382748 9.19092703]]