在numpy中生成随机数的函数之间的差异 [英] Difference between functions generating random numbers in numpy

查看:62
本文介绍了在numpy中生成随机数的函数之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解这些功能之间的区别(如果有的话):

I am trying to understand what is the difference, if any, between these functions:

numpy.random.rand()

numpy.random.random()

numpy.random.uniform()

似乎他们从均匀分布中产生了一个随机样本.那么,该函数中没有任何参数,有什么区别吗?

It seems that they produce a random sample from a uniform distribution. So, without any parameter in the function, is there any difference?

推荐答案

numpy.random.uniform(low=0.0, high=1.0, size=None) -任意范围内的均匀样本

numpy.random.uniform(low=0.0, high=1.0, size=None) - uniform samples from arbitrary range

从均匀分布中抽取样本.
样本在半开区间[low, high)中均匀分布(包括低,但不包括高).换句话说,在给定间隔内的任何值都可能均匀地被绘制.

Draw samples from a uniform distribution.
Samples are uniformly distributed over the half-open interval [low, high) (includes low, but excludes high). In other words, any value within the given interval is equally likely to be drawn by uniform.

numpy.random.random(size=None) -均匀分布在0到1之间

numpy.random.random(size=None) - uniform distribution between 0 and 1

以半开间隔[0.0, 1.0)返回随机浮点数.
结果来自指定时间间隔内的连续均匀"分布.要对Unif[a, b)进行采样,b > arandom_sample by(b-a)的输出乘以并添加a:
(b - a) * random_sample() + a

Return random floats in the half-open interval [0.0, 1.0).
Results are from the "continuous uniform" distribution over the stated interval. To sample Unif[a, b), b > a multiply the output of random_sample by (b-a) and add a:
(b - a) * random_sample() + a

numpy.random.rand(d0, d1, ..., dn) -来自以下示例均匀分布以填充给定形状的数组

numpy.random.rand(d0, d1, ..., dn) - Samples from a uniform distribution to populate an array of a given shape

给定形状的随机值.
创建给定形状的数组,并使用[0, 1)上均匀分布的随机样本传播它.

Random values in a given shape.
Create an array of the given shape and propagate it with random samples from a uniform distribution over [0, 1).

要回答另一个问题,给定所有默认参数,所有功能numpy.random.uniformnumpy.random.randomnumpy.random.rand都是相同的.

To answer your other question, given all default parameters all of the functions numpy.random.uniform, numpy.random.random, and numpy.random.rand are identical.

这篇关于在numpy中生成随机数的函数之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆