numpy.random.
random_sample
(size=None)
返回半开区间内的随机浮点数[0.0,1.0]。
结果来自于规定间隔内的“连续均匀”分布。样本 Unif[a, b), b > a 乘以的输出 random_sample 通过 (b-a) 并添加 a ::
复制代码
1(b - a) * random_sample() + a
参数: | size : int或int的元组,可选 输出形状。如果给定的形状是,例如, |
---|---|
返回: | out : 浮点数或浮点数 形状随机浮动数组 size (除非 |
示例
复制代码
1
2
3
4
5
6>>> np.random.random_sample() 0.47108547995356098 >>> type(np.random.random_sample()) <type 'float'> >>> np.random.random_sample((5,)) array([ 0.30220482, 0.86820401, 0.1654503 , 0.11659149, 0.54323428])
从[-5,0]开始的三乘二随机数数组:
复制代码
1
2
3
4>>> 5 * np.random.random_sample((3, 2)) - 5 array([[-3.99149989, -0.52338984], [-2.99091858, -0.79479508], [-1.23204345, -1.75224494]])
最后
以上就是可耐月饼最近收集整理的关于numpy.random.random_sample用法(python numpy库)的全部内容,更多相关numpy.random.random_sample用法(python内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复