[英]How to write a program using Numpy to generate and print 5 random number between 0 & 1
How to write a program using Numpy to generate and print 5 random number between 0 and 1如何使用 Numpy 编写程序来生成和打印 0 到 1 之间的 5 个随机数
import numpy as np
numbers = np.random.rand(5)
print(numbers)
np.random.rand will produce a sample from the uniform distribution over [0,1] np.random.rand将从 [0,1] 上的均匀分布中生成样本
If you want to generate numbers from a different interval, let's say [a,b], you can use:如果你想从不同的区间生成数字,比如说 [a,b],你可以使用:
import numpy as np
a = 2
b = 4
numbers = a + np.random.rand(5)*(b-a)
print(numbers)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.