Last active
April 22, 2018 23:32
-
-
Save danielrmeyer/22ea82aaa958b69295e779e3097cc7aa to your computer and use it in GitHub Desktop.
Stochastic estimation of pi using dask
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dask.bag as db | |
import random | |
NUM_SAMPLES=100 | |
def inside(p): | |
x, y = random.random(), random.random() | |
return x*x + y*y < 1 | |
def calc_pi(): | |
count = db.from_sequence(range(0, NUM_SAMPLES)).filter(inside).count().compute() | |
return 4.0 * count / NUM_SAMPLES | |
print(calc_pi()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment