各种numpy随机函数之间的区别 [英] Difference between various numpy random functions
问题描述
numpy.random 模块定义了以下4个似乎都返回的函数来自连续均匀分布的float betweeb [0,1.0).这些功能之间有什么区别(如果有)?
The numpy.random module defines the following 4 functions that all seem to return a float betweeb [0, 1.0) from the continuous uniform distribution. What (if any) is the difference between these functions?
random_sample([size])返回半开间隔[0.0,1.0)中的随机浮点数.
random_sample([size]) Return random floats in the half-open interval [0.0, 1.0).
random([size])返回半开间隔[0.0,1.0)中的随机浮点数.
random([size]) Return random floats in the half-open interval [0.0, 1.0).
ranf([size])返回半开间隔[0.0,1.0)中的随机浮点数.
ranf([size]) Return random floats in the half-open interval [0.0, 1.0).
sample([size])返回半开间隔[0.0,1.0)中的随机浮点数.
sample([size]) Return random floats in the half-open interval [0.0, 1.0).
---------------编辑跟随------------------ ---------------------
--------------------------- Edit Follows ---------------------------------------
我在numpy.random
支持@askewchan答案的源代码中找到了以下内容:
I found the following in numpy.random
source code that supports @askewchan's answer:
# Some aliases:
ranf = random = sample = random_sample
__all__.extend(['ranf','random','sample'])
推荐答案
没事.
它们只是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
这篇关于各种numpy随机函数之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!