stats.rv_discrete is not checking that xk values are integers
See original GitHub issuescipy.stats.rv_discrete
requires that the x
input for the values
parameters are integers:
values : tuple of two array_like, optional (xk, pk) where xk are integers and pk are the non-zero probabilities between 0 and 1 with sum(pk) = 1. xk and pk must have the same shape.
Reproducing code example:
The example code:
from scipy import stats
xk = np.arange(7)
pk = (0.1, 0.2, 0.3, 0.1, 0.1, 0.0, 0.2)
custm = stats.rv_discrete(name='custm', values=(xk, pk))
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1)
ax.plot(xk, custm.pmf(xk), 'ro', ms=12, mec='r')
ax.vlines(xk, 0, custm.pmf(xk), colors='r', lw=4)
plt.show()
returns
but if I change to xk = np.linspace(1., 6.9, 7)
I get:
This is a user error with a silent fail. There should be a validation or at least a warning shown.
Scipy/Numpy/Python version information:
1.6.1 1.19.2 sys.version_info(major=3, minor=8, micro=8, releaselevel='final', serial=0)
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
scipy.stats.rv_discrete — SciPy v1.9.3 Manual
(xk, pk) where xk are integers and pk are the non-zero probabilities between 0 and 1 with sum(pk) = 1 . xk and...
Read more >Workaround for 'sum pk not equal to 1' error in scipy's stats. ...
rv_discrete function requires that the sum of the probabilities to be 1 but because of the representation of floats in memory, the sum...
Read more >Source code for scipy.stats._distn_infrastructure
The rule is that if `size` is not None, then `size` gives the # shape of the result (integer values of `size` are...
Read more >Statistics (scipy.stats)
In the examples above, the specific stream of random numbers is not reproducible ... normdiscrete = stats.rv_discrete(values=(gridint, ... np.round(probs, ...
Read more >scipy.stats._distn_infrastructure
However some external (non-SciPy) distributions have not # been updated. ... 0.1, 0.1, 0.0, 0.2) >>> custm = stats.rv_discrete(name='custm', values=(xk, ...
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
See gh-2414. I see this is about direct use ofNot relevant. That was about a shape parameter, notrv_discrete
though, so maybe not as relevant. Just note that we don’t necessarily want allrv_discrete
subclasses to only accept integer input.xk
.After reading this and gh-3758, it is more clear that they are duplicates. Let’s close this and continue in gh-3758.