1

The output should contain a NumPy array with 10 numbers representing the required binomial distribution.

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
Anshul
  • 1,413
  • 2
  • 6
  • 14
Sachin Attri
  • 27
  • 1
  • 7

1 Answers1

1

Perhaps I am missing all of the specifics, but the natural choice would be Scipy's binomial distribution features. You can see the documentation of scipy.stats.binom. Referencing the documentation,

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)
DBat
  • 588
  • 2
  • 11