需要生成一个二项分布,测试 10 次,给定试验次数 (n) 和每次试验的概率 (p)。
输出应包含一个 numpy 数组,其中 10 个数字表示所需的二项式分布。
样本输入:0 10 0.5
预期输出:
[5 6 5 5 5 6 5 7 8 5]
我的代码:
import numpy as np
import pandas as pd
pd.set_option('display.max_columns', 500)
np.random.seed(0)
seed=int(input())
n=int(input())
p=float(input())
i = 1
while i <= n:
x = np.random.binomial(n, p)
s=np.array(x)
print(s)
i += 1
代码输出:
5 6 5 5 5 6 5 7 8 5
输出没有按预期输出我在这里做错了什么?