1

输出应包含一个 NumPy 数组,其中 10 个数字表示所需的二项分布。

import numpy as np 
import pandas as pd
pd.set_option('display.max_columns', 500)
seed=int(input())`enter code here`
n=int(input())
p=float(input())
i = 1`enter code here`
while i < n:
    a = np.random.binomial(n, p)
    s=np.array(a)`enter code here`
    print(s)
    i += 1
4

1 回答 1

1

也许我遗漏了所有细节,但自然的选择是 Scipy 的二项式分布特征。您可以查看scipy.stats.binom的文档。参考文档,

def sample_binomial_size(size, n, p):
    """
    :param size: number of samples to produce
    :param n: number of available values
    :param p: probability shape factor
    """
    from scipy.stats import binom
    return binom.rvs(n, p, size=size)
于 2020-05-16T20:37:47.380 回答