# [Scipy-tickets] [SciPy] #1842: wrong value returned by scipy.stats.binom probability mass function when true probability is 1

SciPy Trac scipy-tickets@scipy....
Thu Feb 14 15:19:08 CST 2013

```#1842: wrong value returned by scipy.stats.binom probability mass function when
true probability is 1
-------------------------+--------------------------------------------------
Reporter:  leflage      |       Owner:  rgommers
Type:  defect       |      Status:  new
Priority:  normal       |   Milestone:  Unscheduled
Component:  scipy.stats  |     Version:  0.11.0
Keywords:               |
-------------------------+--------------------------------------------------

Comment(by leflage):

Hi josefpktd,

I was able to deal with this bug in my own code by creating the class
below.  It works for vectors/arrays, but uses np.where and probably isn't
very efficient and probably doesn't adhere to scipy conventions.

I looked at the source code for R to see if there was a better solution.
It looks like they also use conditional statements to deal with degenerate
cases.  I'm afraid I don't quite grasp your mask solution, and in light of
that and my loose grasp on tricks that could be used to make this more
efficient I don't think I should volunteer.

{{{
class fbin:
def __init__(self, n, p):
self.d = binom(n,p)
self.n = n
self.p = p
def pmf(self, k):
k = np.array(k)
if self.p == 1 and self.n in k:
z = np.zeros(len(k))
z[np.where(k == self.n)] = 1.
return z
elif self.p == 0 and 0 in k:
z = np.zeros(len(k))
z[np.where(k == 0)] = 1.
return z
else:
z = self.d.pmf(k)
return z
}}}

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