BUG: scipy.stats.norm wrong expected value of function when loc is large
See original GitHub issueThe expected value of a normal distribution should be the center of the distribution, but scipy gives wrong results when loc/scale is large.
Reproducing code example:
>>> import scipy.stats as stats
>>> stats.norm.expect(loc=10, scale=1)
10.000000000000004
>>> stats.norm.expect(loc=20, scale=1)
20.0
>>> stats.norm.expect(loc=30, scale=1)
30.0
>>> stats.norm.expect(loc=36, scale=1)
3.3637320653305685e-10
>>> stats.norm.expect(loc=40, scale=1)
1.5746385460369797e-26
>>> stats.norm.expect(loc=10, scale=0.1)
2.3378433179863228e-37
Scipy/Numpy/Python version information:
Scipy 1.1.0
Numpy 1.14.3
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:8 (5 by maintainers)
Top Results From Across the Web
How to use scipy.stats expect function? - python - Stack Overflow
You have understood the manual correctly, but it turns out that if the "loc" is greater than 35.6, then things get abnormal. Otherwise,...
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 >Statistics (scipy.stats) — SciPy v1.9.3 Manual
All continuous distributions take loc and scale as keyword parameters to adjust the location and scale of the distribution, e.g., for the standard...
Read more >SciPy 1.9.0 Release Notes — SciPy v1.9.3 Manual
Speed up the RBFInterpolator evaluation with high dimensional interpolants. ... #8928: BUG: scipy.stats.norm wrong expected value of function when loc…
Read more >scipy.stats.ttest_ind — SciPy v1.9.3 Manual
This is a test for the null hypothesis that 2 independent samples have identical average (expected) values. This test assumes that the populations...
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

The same issue also occurs when using a small loc and a large upper or lower bound:
Could there be a way of throwing a warning or similar when this kind of inconsistencies occur? At least users would be aware that there might be problems with the obtained results.