[英]How to generate random numbers with specific probabilities in python?
例如,
嘗試生成只有0 and 1
的 1000 個隨機數的列表。
聖
0 has the prob of 40%
1 has the prob of 60%
謝謝!
我的概率 = []
for i in range(1000):
#creates one number out of 0 or 1 with prob p 0.4 for 0 and 0.6 for 1
test = numpy.random.choice(numpy.arange(0, 2), p=[0.4, 0.6])
myProb.append(test)
打印(我的問題)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.