text_plain_output_1.png
from collections import Counter

import matplotlib.pyplot as plt

import numpy as np

# Code to plot a function. Borrowed from fastai library.
def plot_func(f, tx=None, ty=None, title=None, min=-2, max=2, figsize=(6,4)):
    x = np.linspace(min,max)
    fig,ax = plt.subplots(figsize=figsize)
    ax.plot(x,f(x))
    if tx is not None: ax.set_xlabel(tx)
    if ty is not None: ax.set_ylabel(ty)
    if title is not None: ax.set_title(title)

red_bag = np.array(['Apple'] * 4 + ['Orange'])
green_bag = np.array(['Orange'] * 9 + ['Apple'])
white_bag = np.array(['Orange'] * 5 + ['Apple'] * 5)

def surprise(probability):
    return np.log2(1 / probability)

P_h = 0.9
P_t = 0.1
S_h = surprise(P_h)
print(f'Surprise of heads is: {round(S_h, 2)}')
S_t = surprise(P_t)
print(f'Surprise of tails is: {round(S_t, 2)}')