question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: misleading documentation in scipy.stats.entropy

See original GitHub issue

Reproducing 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:closed
  • Created 2 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
YairMZcommented, Sep 2, 2021

@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.

0reactions
tirthasheshpatelcommented, Sep 3, 2021

Closed in #14685

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found