From 5f9f8575e8fd29fc533fbb15ec2271de67a0c532 Mon Sep 17 00:00:00 2001 From: 287eb2433e490772bca1c5b6aae5009d <287eb2433e490772bca1c5b6aae5009d@app-learninglab.inria.fr> Date: Fri, 27 Nov 2020 11:51:05 +0000 Subject: [PATCH] no commit message --- module2/exo1/toy_notebook_en.ipynb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/module2/exo1/toy_notebook_en.ipynb b/module2/exo1/toy_notebook_en.ipynb index df81e94..c7406a9 100644 --- a/module2/exo1/toy_notebook_en.ipynb +++ b/module2/exo1/toy_notebook_en.ipynb @@ -66,7 +66,7 @@ "metadata": {}, "source": [ "## Using a surface fraction argument\n", - "A method that is easier to understand and does not make use of the sin function is based on the fact that if $X \\sim U(0,1)$ $Y \\sim U(0,1)$, then $P[X^2+Y^2\\leq 1] = \\pi/4$ (see [\"Monte Carlo method\" on Wikipedia](https://en.wikipedia.org/wiki/Monte_Carlo_method)). The following code uses this approach:" + "A method that is easier to understand and does not make use of the sin function is based on the fact that if $X\\sim U(0,1)$ and $Y\\sim U(0,1)$, then $P[X^2+Y^2\\leq 1] = \\pi/4$ (see [\"Monte Carlo method\" on Wikipedia](https://en.wikipedia.org/wiki/Monte_Carlo_method)). The following code uses this approach:" ] }, { @@ -88,15 +88,17 @@ } ], "source": [ - "%matplotlib inline\n", + "%matplotlib inline \n", "import matplotlib.pyplot as plt\n", "\n", "np.random.seed(seed=42)\n", "N = 1000\n", "x = np.random.uniform(size=N, low=0, high=1)\n", "y = np.random.uniform(size=N, low=0, high=1)\n", + "\n", "accept = (x*x+y*y) <= 1\n", "reject = np.logical_not(accept)\n", + "\n", "fig, ax = plt.subplots(1)\n", "ax.scatter(x[accept], y[accept], c='b', alpha=0.2, edgecolor=None)\n", "ax.scatter(x[reject], y[reject], c='r', alpha=0.2, edgecolor=None)\n", -- 2.18.1