<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Oct 8, 2017 at 9:59 PM, Juan Nunez-Iglesias <span dir="ltr"><<a href="mailto:jni.soma@gmail.com" target="_blank">jni.soma@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">



<div>
<div name="messageBodySection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif">I’m not familiar with this part of the codebase, but after a bit of playing around, I think this isn’t yet implemented, maybe because it’s too hard? The relevant in scipy/stats/_distn_<wbr>infrastructure.py call is:
<div><br></div>
<div>-> 2775         m = arange(int(self.a), k+1)<br></div>
<div><br></div>
<div>self.a is the lower bound of the cdf to be computed, in this case, an array [0, 0, 0] to match the input N = self.b = [2, 4, 6]. The problem of course is that there is no general way to vectorize np.arange, because you would get a jagged array.</div>
<div><br></div>
<div>I hope someone with more knowledge of the library will chime in, but I think you’ll have to implement your own looping logic in the short-to-medium term…</div>
<div><br></div>
<div>Juan.</div>
</div>
<div name="messageReplySection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif"><div><div class="gmail-h5"><br>
On 7 Oct 2017, 8:36 PM +1100, Giovanni Bonaccorsi <<a href="mailto:giovanni.bonaccorsi@gmail.com" target="_blank">giovanni.bonaccorsi@gmail.com</a><wbr>>, wrote:<br>
</div></div><blockquote type="cite" style="margin:5px;padding-left:10px;border-left:thin solid rgb(26,188,156)"><div><div class="gmail-h5">
<div dir="ltr">
<div>Hi everyone, </div>
<div>first post here. I have a doubt about broadcasting in scipy. </div>
<div><br></div>
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: 
<div><br></div>
<div>
<pre style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:11.9px;margin-top:0px;margin-bottom:16px;word-wrap:normal;padding:16px;overflow:auto;line-height:1.45;background-color:rgb(246,248,250);border-radius:3px;color:rgb(36,41,46)"><code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:11.9px;padding:0px;margin:0px;background:transparent;border-radius:3px;word-break:normal;border:0px;display:inline;overflow:visible;line-height:inherit;word-wrap:normal">TypeError: only length-1 arrays can be converted to Python scalars</code></pre></div>
<div>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? </div>
<div><br></div>
<div>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.</div>
<div><br></div>
<div>
<pre style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:11.9px;margin-top:0px;margin-bottom:16px;word-wrap:normal;padding:16px;overflow:auto;line-height:1.45;background-color:rgb(246,248,250);border-radius:3px;color:rgb(36,41,46)"><code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:11.9px;padding:0px;margin:0px;background:transparent;border-radius:3px;word-break:normal;border:0px;display:inline;overflow:visible;line-height:inherit;word-wrap:normal">import numpy as np
from scipy.stats import hypergeom

# this works
x = np.array([[1,2,3],[4,5,6],[11,<wbr>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)</code></pre></div></div></div></div></blockquote></div></div></blockquote><div><br></div><div>I haven't seriously looked at the distribution code in a while.</div><div><br></div><div>The reason was and, I guess, is that the support of a distribution is not vectorized, i.e. the bounds.a and .b.</div><div>This means that in distributions where the support depends on a shape parameter some methods are not vectorized in that parameter. </div><div>It might work in some cases but there is no generic support for it in the base classes. AFAIK .a and .b are always scalar</div><div><br></div><div>Looks like <a href="https://github.com/scipy/scipy/issues/1320">https://github.com/scipy/scipy/issues/1320</a> is still open.</div><div>However, I don't remember much discussion about the discrete distributions like hypergeom.</div><div><br></div><div>Josef</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div name="messageReplySection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif"><blockquote type="cite" style="margin:5px;padding-left:10px;border-left:thin solid rgb(26,188,156)"><div><div class="gmail-h5"><div dir="ltr">
<div><br></div>
<div>Thanks a lot for the support.,<br></div>
<div>Giovanni</div>
<div><br></div>
</div></div></div>
______________________________<wbr>_________________<br>
SciPy-User mailing list<br>
<a href="mailto:SciPy-User@python.org" target="_blank">SciPy-User@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/scipy-user" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/scipy-user</a><br></blockquote>
<div></div>
</div>
</div>

<br>______________________________<wbr>_________________<br>
SciPy-User mailing list<br>
<a href="mailto:SciPy-User@python.org">SciPy-User@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/scipy-user" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/scipy-user</a><br>
<br></blockquote></div><br></div></div>