From 8099a2782f45174f7aa661e952d44c972a1df539 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Tue, 20 Dec 2022 10:28:03 -0500 Subject: [PATCH] Backport PR #24785: Fix random generation of single floats --- examples/animation/bayes_update.py | 2 +- examples/animation/strip_chart.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/animation/bayes_update.py b/examples/animation/bayes_update.py index d1c43c71fa31..6ac226d0d023 100644 --- a/examples/animation/bayes_update.py +++ b/examples/animation/bayes_update.py @@ -47,7 +47,7 @@ def __call__(self, i): return self.line, # Choose success based on exceed a threshold with a uniform pick - if np.random.rand(1,) < self.prob: + if np.random.rand() < self.prob: self.success += 1 y = beta_pdf(self.x, self.success + 1, (i - self.success) + 1) self.line.set_data(self.x, y) diff --git a/examples/animation/strip_chart.py b/examples/animation/strip_chart.py index 9fab4aa66f12..7a7decc7004c 100644 --- a/examples/animation/strip_chart.py +++ b/examples/animation/strip_chart.py @@ -37,7 +37,7 @@ def update(self, y): t = self.tdata[0] + len(self.tdata) * self.dt self.tdata.append(t) - self.ydata.append(float(y)) + self.ydata.append(y) self.line.set_data(self.tdata, self.ydata) return self.line, @@ -45,11 +45,11 @@ def update(self, y): def emitter(p=0.1): """Return a random value in [0, 1) with probability p, else 0.""" while True: - v = np.random.rand(1) + v = np.random.rand() if v > p: yield 0. else: - yield np.random.rand(1) + yield np.random.rand() # Fixing random state for reproducibility