from datascience import *
import numpy as np
Table.interactive_plots()
from ipywidgets import interact, widgets
from IPython.display import display
coin = np.array(['heads', 'tails'])
coin
flips = np.random.choice(coin, size = 10)
flips
# Array of 10 elements – True if flip was 'heads', False otherwise
flips == 'heads'
# Number of heads
np.count_nonzero(flips == 'heads')
Idea:
num_heads_arr = np.array([])
for i in np.arange(10000):
flips = np.random.choice(coin, size = 100)
heads = np.count_nonzero(flips == 'heads')
num_heads_arr = np.append(num_heads_arr, heads)
num_heads_arr
len(num_heads_arr)
Table().with_columns('Number of Heads', num_heads_arr) \
.hist(density = False, bins = np.arange(25.5, 76.5), title = 'Empirical Distribution of 100 Coin Flips')