numpy.random.RandomState.rand#
method
- random.RandomState.rand(d0, d1, ..., dn)#
给定形状的随机值.
备注
这是一个为从 Matlab 移植代码的用户提供的便利函数,它包装了
random_sample.该函数接受一个元组来指定输出的大小,这与其他 NumPy 函数(如numpy.zeros和numpy.ones)一致.创建一个给定形状的数组,并用来自
[0, 1)上的均匀分布的随机样本填充它.- 参数:
- d0, d1, …, dnint, optional
返回数组的维度,必须是非负的.如果没有给出参数,则返回一个 Python 浮点数.
- 返回:
- out : ndarray, shape
(d0, d1, ..., dn)ndarray, shape(d0, d1, ..., dn) 随机值.
- out : ndarray, shape
参见
示例
>>> np.random.rand(3,2) array([[ 0.14022471, 0.96360618], #random [ 0.37601032, 0.25528411], #random [ 0.49313049, 0.94909878]]) #random