gpt4 book ai didi

python - 在numpy中生成随机数的函数之间的区别

转载 作者:太空狗 更新时间:2023-10-29 23:58:35 24 4
gpt4 key购买 nike

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

numpy.random.rand()

numpy.random.random()

numpy.random.uniform()

他们似乎从均匀分布中生成随机样本。那么,函数中没有任何参数,有什么区别吗?

最佳答案

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

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 之间均匀分布

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) - 来自均匀分布的样本以填充给定形状的数组

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 相同。

关于python - 在numpy中生成随机数的函数之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30762832/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com