A probability mass function (PMF) assigns a probability to each possible value of a discrete random variable. For a binomial distribution, it answers questions such as: “What is the probability of exactly 7 successes in 10 trials?” section 3.7
A binomial PMF uses three parameters:
- n: the number of trials. section 3.7
- k: the number of successes being evaluated. section 3.7
- p: the probability of success on one trial. section 3.7
Ten trials with 90% success probability
Using scipy.stats.binom.pmf(k=7, n=10, p=.9) gives about 0.057, or 5.7%. To find the probability of 8 or fewer successes, sum the PMF values for k from 0 through 8, giving about 26.4%. section 3.7
import numpy as np
from scipy.stats import binom
n = 10 #1
p = 0.9 #2
k = np.arange(0, n + 1) #3
y = binom.pmf(k, n, p) #4
for _k, _y in zip(k, y): #5
print(f"The probability of {_k}/{n} successes is {_y:.4f}") #6
Inspect the PMF for every possible number of successes from 0 through 10. section 3.7


