[SciPy-User] Question about the behavior of hypergeom.cdf

Giovanni Bonaccorsi giovanni.bonaccorsi at gmail.com
Sat Oct 7 05:35:24 EDT 2017


Hi everyone,
first post here. I have a doubt about broadcasting in scipy.

I'm trying to apply broadcasting with hypergeom. The problem is that while
hypergeom.pmf() accept my arrays without complaining the hypergeom.cdf()
function throws out this error:

TypeError: only length-1 arrays can be converted to Python scalars

Now, I don't know if this is the expected behavior of the function, but
from the documentation it doesn't seem necessary to take particular care to
arrays argument in the hypergeom.cdf() function with respect to
hypergeom.pmf(). Is that right or have I missed something?

I'm attaching a minimal example to reproduce the error, I'm using Python2.7
through Anaconda with scipy and numpy updated to the last releases.

import numpy as np
from scipy.stats import hypergeom

# this works
x = np.array([[1,2,3],[4,5,6],[11,12,13]])
M,n,N = [20,7,12]
hypergeom.pmf(x,M,n,N)
hypergeom.cdf(x,M,n,N)

# this works
M=np.array([25])
n=np.array([3,6,9])
N=np.array([2,4,6])
hypergeom.pmf(x,M,n,N)

# this doesn't work
hypergeom.cdf(x,M,n,N)


Thanks a lot for the support.,
Giovanni
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-user/attachments/20171007/65b906ce/attachment.html>


More information about the SciPy-User mailing list