January 2020
Intermediate to advanced
432 pages
10h 18m
English
If you are still having problems grasping this concept, visualizing this example may be more helpful. Run the exercise in the next section if you want to visualize what this sampling looks like:
pip install matplotlib
import matplotlib.pyplot as pltfrom random import randomins = 0n = 1000x_ins = []y_ins = []x_outs = []y_outs = []for _ in range(n): x = (random()-.5) * 2 y = (random()-.5) * 2 if (x**2+y**2) <= 1: ins += 1 x_ins.append(x) y_ins.append(y) else: x_outs.append(x) y_outs.append(y)pi = 4 * ins/nprint(pi)fig, ...
Read now
Unlock full access