You are on page 1of 2

Math Stats HW1 9/17/19, 1'31 PM

In [7]: import matplotlib.pyplot as plt


import numpy as np

In [10]: trials = 1000 # number of flips


heads_or_tails = np.zeros((trials,1)) #storage of coin flip results
trial_numbers = range(0,trials) #label of trials
for n in trial_numbers:
heads_or_tails[n] = np.random.binomial(size=1,n=1,p=0.3)

In [11]: # add up the cumulative number of heads we've gotten


cumulative_heads=np.cumsum(heads_or_tails)

In [12]: # divide cumulative number by the trial number


cumulative_heads_divided_by_trial = np.divide(cumulative_heads,trial_n
umbers)

/Users/feihuyan/anaconda3/lib/python3.7/site-packages/ipykernel_laun
cher.py:1: RuntimeWarning: invalid value encountered in true_divide
"""Entry point for launching an IPython kernel.

In [13]: plt.plot(trial_numbers, cumulative_heads_divided_by_trial)


plt.title('Chapter, Problem 21')
plt.show()

In [1]: import matplotlib.pyplot as plt


import numpy as np

http://localhost:8890/nbconvert/html/Math%20Stats%20HW1.ipynb?download=false Page 1 of 2
Math Stats HW1 9/17/19, 1'31 PM

In [3]: #Generate random normal numbers


x = np.random.normal(loc=0,scale=1.0,size=(10000,1))
#Get the exponentials to x as output y
y = np.exp(x)

In [6]: #Plot with 500 bins


plt.hist(y,500)
plt.title('Chapter 2, Problem 13B')
plt.show()

In [ ]:

http://localhost:8890/nbconvert/html/Math%20Stats%20HW1.ipynb?download=false Page 2 of 2

You might also like