[SciPy-User] binom pdf error

Warren Weckesser warren.weckesser at enthought.com
Fri Jul 22 17:38:44 EDT 2011


On Fri, Jul 22, 2011 at 3:31 PM, Antonio Ingargiola <tritemio at gmail.com>wrote:

> Hi to the list,
>
> I got an error using the pdf method on the binom distribution. Same error
> happens on scipy 0.8 and scipy 0.9 (respectively ubuntu distribution and
> pythonxy on windows).
>
> The error is the following:
>
> In [1]: from scipy.stats.distributions import binom
>
> In [2]: b = binom(20,0.8)
>
> In [3]: b.rvs()
> Out[3]: 17
>
> In [4]: b.pdf(2)
> ---------------------------------------------------------------------------
> AttributeError                            Traceback (most recent call last)
>
> C:\Users\anto\.xy\startups\<ipython console> in <module>()
>
> C:\Python26\lib\site-packages\scipy\stats\distributions.pyc in pdf(self, x)
>     333
>     334     def pdf(self, x):    #raises AttributeError in frozen discrete
> distribution
> --> 335         return self.dist.pdf(x, *self.args, **self.kwds)
>     336
>     337     def cdf(self, x):
>
> AttributeError: 'binom_gen' object has no attribute 'pdf'
>
> In [5]:
>
>
> Is this known problem? How can I get the binomial pdf, is there a
> workaround?
>


Since binom is a discrete distribution, you want the pmf method:

In [32]: b = binom(20, 0.8)

In [33]: b.pmf(2)
Out[33]: 3.1876710400000011e-11

In [34]: b.pmf(18)
Out[34]: 0.13690942867206304


The behavior that you observed still looks like a bug to me--why does binom
even have a pdf method, if calling it just raises a cryptic exception?

Warren



>
> Many thanks,
> Antonio
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20110722/37100f0f/attachment.html>


More information about the SciPy-User mailing list