Binomial Probability Mass Function in Python
I am using Python3 to calculate the probability weighting function (PMF) of this example on wikipedia:
I tried following this meager documentation:
https://docs.scipy.org/doc/scipy-0.19.0/reference/generated/scipy.stats.binom.html
The documentation clearly states:
Notes
The probability mass function for binom is:
binom.pmf(k) = choose(n, k) * p**k * (1-p)**(n-k)
for k in {0, 1,..., n}.
binom takes n and p as shape parameters.
Ok, I tried to implement this with the wikipedia example in mind. This is my code:
from scipy.stats import binom n = 6 p = 0.3 binom.pmf(k) = choose(n, k) * p**k * (1-p)**(n-k) print (binom.pmf(1))
However, I am getting this error message:
File "binomial-oab.py", line 7
binom.pmf(k) = choose(n, k) * p**k * (1-p)**(n-k)
^
SyntaxError: can't assign to function call
How can I solve this?
+3
user7120460
source
to share