各种numpy随机函数之间的差异

Dha*_*ara 30 python numpy

所述numpy.random模块定义了以下4个功能,所有似乎从连续均匀分布返回浮点betweeb [0,1.0).这些功能之间的区别是什么(如果有的话)?

random_sample([size])在半开区间[0.0,1.0]中返回随机浮点数.

random([size])在半开区间[0.0,1.0]中返回随机浮点数.

ranf([size])在半开区间[0.0,1.0]中返回随机浮点数.

sample([size])在半开区间[0.0,1.0]中返回随机浮点数.

---------------------------编辑关注--------------------- ------------------

我在numpy.random源代码中找到了以下支持@askewchan的答案:

# Some aliases:
ranf = random = sample = random_sample
__all__.extend(['ranf','random','sample'])
Run Code Online (Sandbox Code Playgroud)

ask*_*han 38

没有.

他们只是别名random_sample:

In [660]: np.random.random
Out[660]: <function random_sample>

In [661]: np.random.ranf
Out[661]: <function random_sample>

In [662]: np.random.sample
Out[662]: <function random_sample>

In [663]: np.random.random_sample is np.random.random
Out[663]: True

In [664]: np.random.random_sample is np.random.ranf
Out[664]: True

In [665]: np.random.random_sample is np.random.sample
Out[665]: True
Run Code Online (Sandbox Code Playgroud)

  • 这真可笑.是什么原因? (3认同)