Simulate a random experiment of tossing a coin 10000 times and determine the count of Heads.
Hint: Define a binomial distribution with n = 1 and p = 0.5.
Use binom function from scipy.stats.
Set the random seed to 1.
Draw a sample of 10000 elements from defined distribution.
Assume the values 0 and 1 represent Heads and Tails respectively.
Count the number of heads and display it. Make used of bincount method, available in numpy.
I found an answer to it but it was not from the scipy.stats package as asked, it was from random package. Below is my attempt but the answer is not as expected. Kindly help me correct my mistake.
import scipy as sp from scipy import stats import numpy as np import random from scipy.stats import binom data_binom = binom.rvs(n=1,p=0.5,size=10000) np.random.seed(1) #print(data_binom) y = np.bincount(data_binom) head = print(y[0]) print(head)