[SciPy-user] coercion error when using stats.distirbutions.entropy

Johann Cohen-Tanugi cohen@slac.stanford....
Wed Nov 14 14:00:35 CST 2007


Hugues Salamin wrote:
> Hi,
>
> I come against a strange error when I compute the entropy of discrete
> random variable. Here is a small script
> showing this problem (python 2.4.4, scipy 0.5.2 and numpy 1.0.1):
>
> [code]
> #!/usr/bin/env python2.4
>
> from scipy import stats
>
> val = ( (1,2,3),(0.5,0.25,0.25))
> dist = stats.distributions.rv_discrete(name="temp", values = val)
> dist.pmf(2)
> print dist.entropy()
> [/code]
>
> I code the following exception:
>
> Traceback (most recent call last):
>   File "./error.py", line 8, in ?
>     print dist.entropy()
>   File "/usr/lib/python2.4/site-packages/scipy/stats/distributions.py",
> line 3787, in entropy
>     place(output,cond0,self.vecentropy(*goodargs))
>   File "/usr/lib/python2.4/site-packages/numpy/lib/function_base.py",
> line 856, in __call__
>     _res = array(self.ufunc(*args),copy=False).astype(self.otypes[0])
> TypeError: function not supported for these types, and can't coerce
> safely to supported types
>
>
> If a remove the call to pmf, the error disappears. I tried to look
> under the hood what was happening but I'm totally at lost,
>
> Any help appreciated
>
> Hugues
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>   

Your code snippet works for me with python 2.5, and numpy/scipy 
1.0.3.1/0.6.0
Johann


More information about the SciPy-user mailing list