# [Scipy-tickets] [SciPy] #1291: stats.discrete distributions hypergeom.sf exception

SciPy Trac scipy-tickets@scipy....
Fri Oct 22 10:56:41 CDT 2010

```#1291: stats.discrete distributions hypergeom.sf exception
-------------------------+--------------------------------------------------
Reporter:  josefpktd    |       Owner:  somebody
Type:  defect       |      Status:  needs_review
Priority:  normal       |   Milestone:  0.9.0
Component:  scipy.stats  |     Version:  0.7.0
Keywords:               |
-------------------------+--------------------------------------------------
Changes (by jledoux):

* status:  new => needs_review

Comment:

I provided a solution on [http://stackoverflow.com/questions/3812896/can-
some-explain-this-strange-behavior-of-the-hypergeometric-distribution-in-
scip/3997870#3997870
stackoverflow].  Basically around line 3966 in
scipy/stats/distributions.py in the sf function in the rv_discrete class,
if you copy the if output.ndim == 0: return output [()] from below the
place line to above the place line, the IndexError goes away on the place
call goes away.

E.g., change scipy/stats/distributions.py to

{{{
class rv_discrete(rv_generic):
...

def sf(self,k,*args,**kwds):
"""
...
"""
loc= kwds.get('loc')
args, loc = self._fix_loc(args, loc)
k,loc = map(arr,(k,loc))
args = tuple(map(arr,args))
k = arr(k-loc)
cond0 = self._argcheck(*args)
cond1 = (k >= self.a) & (k <= self.b)
cond2 = (k < self.a) & cond0
cond = cond0 & cond1
output = zeros(shape(cond),'d')
place(output,(1-cond0)*(cond1==cond1),self.badvalue)
place(output,cond2,1.0)
goodargs = argsreduce(cond, *((k,)+args))
if output.ndim == 0:
return output[()]
place(output,cond,self._sf(*goodargs))
if output.ndim == 0:
return output[()]
return output

}}}

--
Ticket URL: <http://projects.scipy.org/scipy/ticket/1291#comment:3>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.
```

More information about the Scipy-tickets mailing list