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

Hugues Salamin hugues.salamin@gmail....
Wed Nov 14 11:13:32 CST 2007


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


More information about the SciPy-user mailing list