在numpy范围内采样随机浮点数 [英] sampling random floats on a range in numpy

查看:1347
本文介绍了在numpy范围内采样随机浮点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在numpy中以间隔[a,b]采样随机浮点数?不仅是整数,而且是任何实数.例如,

How can I sample random floats on an interval [a, b] in numpy? Not just integers, but any real numbers. For example,

random_float(5, 10)

将返回[5, 10]之间的随机数.谢谢.

would return random numbers between [5, 10]. thanks.

推荐答案

The uniform distribution would probably do what you are asking.

np.random.uniform(5,10) # A single value
np.random.uniform(5,10,[2,3]) # A 2x3 array

这篇关于在numpy范围内采样随机浮点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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