Skip to content

Commit 360de1b

Browse files
BUG: random: Fix handling of a=0 for numpy.random.weibull.
Before this fix, np.random.weibull(a=0) often returned inf (and in theory could have returned 1). It should only return 0. Closes numpygh-12371.
1 parent e34f5bb commit 360de1b

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

‎numpy/random/mtrand/distributions.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,9 @@ double rk_pareto(rk_state *state, double a)
650650

651651
double rk_weibull(rk_state *state, double a)
652652
{
653+
if (a == 0.0) {
654+
return 0.0;
655+
}
653656
return pow(rk_standard_exponential(state), 1./a);
654657
}
655658

‎numpy/random/tests/test_random.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,8 @@ def test_weibull(self):
942942
assert_array_almost_equal(actual, desired, decimal=15)
943943

944944
def test_weibull_0(self):
945-
assert_equal(np.random.weibull(a=0), 0)
945+
np.random.seed(self.seed)
946+
assert_equal(np.random.weibull(a=0, size=12), np.zeros(12))
946947
assert_raises(ValueError, np.random.weibull, a=-0.)
947948

948949
def test_zipf(self):

0 commit comments

Comments
 (0)