From f8f37c30090a82f47ea0e55f03cd3025c06481d5 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 20 Dec 2022 03:18:36 -0500 Subject: [PATCH] Fix random generation of single floats Passing 1 means we get a 1D array with a single element, but passing nothing means a 0D array, aka a single float. --- 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 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy