https://www.hackerrank.com/challenges/s10-poisson-distribution-1
In this challenge, we learn about Poisson distributions. Check out the Tutorial tab for learning materials!
A random variable, , follows Poisson distribution with mean of . Find the probability with which the random variable is equal to .
The first line contains 's mean. The second line contains the value we want the probability for:
2.5
5
If you do not wish to read this information from stdin, you can hard-code it into your program.
Print a single line denoting the answer, rounded to a scale of decimal places (i.e., format).
In [19]:
import math
from matplotlib import pylab as plt
%matplotlib inline
In [20]:
def posion_dist(m, k):
return (m**k * math.e**(-m)) / math.factorial(k)
In [34]:
posion_dist(2, 3)
Out[34]:
In [30]:
N = range(1, 20)
M = 7
plt.plot(N, [posion_dist(M, i) for i in N])
Out[30]: