[SciPy-Dev] warnings in scipy.stats.entropy
Skipper Seabold
jsseabold at gmail.com
Mon May 21 18:39:43 EDT 2012
Currently in scipy.stats.entropy if you are not ignoring them you will
see warnings when the function is given a probability of zero even
though the case of zero is specifically handled in the function.
Rightly or wrongly this makes me cringe. What do people think about
fixing this by using seterr explicitly in the function or masking the
zeros. Eg.,
import numpy as np
from scipy.stats import entropy
prob = np.random.uniform(0,20, size=10)
prob[5] = 0
prob = prob/prob.sum()
np.seterr(all = 'warn')
entropy(prob) # too loud
Instead we could do (within entropy)
oldstate = np.geterr()
np.seterr(divide='ignore', invalid='ignore')
entropy(prob)
np.seterr(**oldstate)
or just mask the zeros in the first place if this is too much
idx = prob > 0
-np.sum(prob[idx] * np.log(prob[idx]))
Thoughts?
Skipper
More information about the SciPy-Dev
mailing list