I have this code:
import sys
from scipy.stats import binom
def mcnemar_midp(b, c):
n = b + c
x = min(b, c)
dist = binom(n, .5)
p = 2. * dist.cdf(x)
midp = p - dist.pmf(x)
return midp
#get numbers from user
num1 = sys.argv[1]
num2 = sys.argv[2]
# calculate the result
myresult = mcnemar_midp(num1, num2)
# Display the sum
print myresult
which does not work if I call it like this: python mcnemar.py 87 89
However, if I hard-code 2 values for num1 and num2 it works fine. The error I get is the following:
Traceback (most recent call last):
File "mcnemar.py", line 28, in <module>
myresult = mcnemar_midp(num1, num2)
File "mcnemar.py", line 19, in mcnemar_midp
p = 2. * dist.cdf(x)
File "/usr/lib/python2.7/dist-packages/scipy/stats/distributions.py", line 440, in cdf
return self.dist.cdf(x, *self.args, **self.kwds)
File "/usr/lib/python2.7/dist-packages/scipy/stats/distributions.py", line 6635, in cdf
k = asarray((k-loc))
TypeError: unsupported operand type(s) for -: 'numpy.ndarray' and 'numpy.ndarray'
but this in only if I try to pass the numbers from the command line, if I write them inside the code, it works. Please help me, I am new to python!