BUG: misleading documentation in scipy.stats.entropy
See original GitHub issueReproducing Code Example
The entropy function allows calculation of entropy along an axis for multi-variate distributions. It works as expected, and returns an ndarray as a result. However in the documentation, the return value is specified as a float (which is indeed returned for univariate distributions).
Thus the problem is in the documentation, and not the implementation itself. Additionally, as a consequence the IDE flags this as a type mismatch when type hinting is used as it assumes the function really return a float and not an array.
To reproduce:
from scipy.stats import entropy
import numpy as np
pk = np.array([[2/3, 1/3],[1/3, 2/3]])
e = entropy(pk)
### SciPy/NumPy/Python version information
`1.7.1 1.21.2 sys.version_info(major=3, minor=9, micro=6, releaselevel='final', serial=0)`
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (13 by maintainers)
Top Results From Across the Web
bugs stats entropy · Issue #2765 · scipy/scipy - GitHub
Notes: I wrote the script originally for scipy 0.9 and python 2.6 (no xlogy); it uses an old copy of the distribution cases...
Read more >scipy.stats.entropy — SciPy v1.9.3 Manual
Calculate the entropy of a distribution for given probability values. If only probabilities pk are given, the entropy is calculated as S =...
Read more >Statistics (scipy.stats) — SciPy v1.9.3 Manual
The distributions have been tested over some range of parameters; however, in some corner ranges, a few incorrect results may remain. The maximum...
Read more >scipy.stats.norm — SciPy v1.9.3 Manual
A normal continuous random variable. The location ( loc ) keyword specifies the mean. The scale ( scale ) keyword specifies the standard...
Read more >scipy.stats.t — SciPy v1.9.3 Manual
(Differential) entropy of the RV. fit(data). Parameter estimates for generic data. See scipy.stats.rv_continuous.fit for detailed documentation of the ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@tupui Thanks for the quick response. I’d love to help and make a PR. The truth is however, that my coding experience has been mostly on my my own projects, and therefore I don’t really know what exactly do I need to do. If you could direct me, I’d be happy to help.
Closed in #14685