numpy.random模块定义了以下 4 个函数,它们似乎都从连续均匀分布中返回一个介于 [0, 1.0) 之间的 float 。这些功能之间有什么区别(如果有的话)?
random_sample([size]) Return random floats in the half-open interval [0.0, 1.0).
random([size]) Return random floats in the half-open interval [0.0, 1.0).
ranf([size]) Return random floats in the half-open interval [0.0, 1.0).
sample([size]) Return random floats in the half-open interval [0.0, 1.0).
--------------- 编辑关注 ------------------ ---------------------
我在 numpy.random
源代码中发现了以下支持@askewchan 的答案:
# 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
关于python - 各种numpy随机函数之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18829185/