import numpy as np import matplotlib.pyplot as plt from scipy.stats import poisson mu = 4.5 E = 0. x = np.linspace(0.,15.,16) y = poisson.pmf(x,mu) for n,p in zip(x,y): E += p*n print("Expectation:", E) fig = plt.figure(figsize=(6,6), dpi=80) plt.bar(x,y) plt.show()