## Reminder: go up to 'File' and 'Make a copy' before running this notebook. Change the name to something that includes your NetID, e.g. 'coin-flips-titus'.¶

In [1]:
import random

# flip a coin
random.choice([0, 1])

Out[1]:
0
In [2]:
N = 100
flips = []
for i in range(N):
flip = random.choice([0, 1])
flips.append(flip)

print flips

[1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0]

In [3]:
print sum(flips) / float(len(flips))

0.47

In [4]:
hist(flips)

Out[4]:
(array([53,  0,  0,  0,  0,  0,  0,  0,  0, 47]),
array([ 0. ,  0.1,  0.2,  0.3,  0.4,  0.5,  0.6,  0.7,  0.8,  0.9,  1. ]),
<a list of 10 Patch objects>)
In [5]:
# write a function to perform many flips
def flip_N(N):
flips = []
for i in range(N):
flip = random.choice([0, 1])
flips.append(flip)

return sum(flips) / float(N)

avg = flip_N(100)
print avg

0.46

In [6]:
# now perform many trials, and show the distribution
n_trials = 500
trials = []
N = 100

for i in range(n_trials):
avg = flip_N(N)
trials.append(avg)

In [7]:
hist(trials)

Out[7]:
(array([  8,  19,  54, 112, 134,  94,  54,  15,   6,   4]),
array([ 0.37 ,  0.399,  0.428,  0.457,  0.486,  0.515,  0.544,  0.573,
0.602,  0.631,  0.66 ]),
<a list of 10 Patch objects>)
In [8]:
ls

coin-flips-evokerr.ipynb
coin-flips-hljordt.ipynb
coin-flips.ipynb
coin-flips-lnj204.ipynb
coin-flips-mherrmannsfeldt.ipynb
coin-flips-qchrist2.ipynb
coin-flips-Richard.ipynb
filter-blast-csv-hljordt.ipynb
filter-blast-csv.ipynb
filter-blast-csv_qchrist2.ipynb
graph-blast-bitscore-Copy0.ipynb
graph-blast-bitscore-Copy6-Copy0.ipynb
graph-blast-bitscore-Copy6.ipynb
graph-blast-bitscore-evokerr.ipynb
graph-blast-bitscore.ipynb
graph-blast-bitscore-leonard.ipynb
graph-blast-bitscore-lnj204.ipynb
graph-blast-bitscore-mherrmannsfeldt.ipynb
graph-blast-bitscore-qchrist2.ipynb
graph-blast-bitscore-Richard.ipynb
graph-blast-bitscore-sr320.ipynb
hljordt.ipynb
kmer-abundance-hljordt.ipynb
kmer-abundance.ipynb
kmer-abundance-lnj204.ipynb
kmer-abundance-mherrmannsfeldt.ipynb
kmer-abundance-qchrist2.ipynb
kmer-abundance-Richard.ipynb
kmer-abundance-titus.ipynb
monty-hall-evokerr.ipynb
monty-hall-hljordt.ipynb
monty-hall.ipynb
monty-hall-lnj204.ipynb
monty-hall-mherrmannsfeldt.ipynb
monty-hall-qchrist2.ipynb
monty-hall-Richard.ipynb
monty-hall-titus.ipynb