NOTE: In this notebook I use the stats
sub-module of scipy
for all statistics functions, including generation of random numbers. There are other modules with some overlapping functionality, e.g., the regular python random module, and the scipy.random
module, but I do not use them here. The stats
sub-module includes tools for a large number of distributions, it includes a large and growing set of statistical functions, and there is a unified class structure. (And namespace issues are minimized.) See https://docs.scipy.org/doc/scipy/reference/stats.html.
import numpy as np
from scipy import stats
For each of the draws, the probability of getting a heart is $\frac{1}{4}$. The probability of getting $k$ successes in $n$ independent trials, where the $p$ is the probability of success in an indvidual trial is given by the binomial distribution stats.binom.pmf(k,n,p)
:
for k in range(7):
n = 6
p = 0.25
print("The probability of",k,"hearts is", stats.binom.pmf(k,n,p))
version_information
is from J.R. Johansson (jrjohansson at gmail.com); see Introduction to scientific computing with Python for more information and instructions for package installation.
version_information
is installed on the linux network at Bucknell
%load_ext version_information
version_information scipy, matplotlib