简体   繁体   English

np.random.choice - 不能指定硬币翻转次数

[英]np.random.choice - can't specify number of coin flips

I'm trying to produce a million results of 3 bias coin flips - random.randint allows me to specify the number of flips but random.choice seems to only let me specify the size.我试图产生 3 次偏置硬币翻转的一百万个结果 - random.randint 允许我指定翻转次数,但 random.choice 似乎只让我指定大小。 What's I'm trying to get is: million results of 3 flips each with 60% chance of heads on a coin.我想要得到的是:每次翻转 3 次的百万结果,硬币正面朝上的几率为 60%。

Seems like you want this:好像你想要这个:

np.random.choice([0, 1], size = (10**6, 3), p = [.4, .6])

or或者

(np.random.rand(10**6, 3) < .6).astype(int)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM