Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. import numpy
  2. import matplotlib.pyplot as plt
  3.  
  4. N = 1000000
  5. x = numpy.random.uniform( low=-1, high=1, size=[N, 1])
  6. y = numpy.random.uniform( low=-1, high=1, size=[N, 1])
  7.  
  8. inside_bool = (x**2 + y**2) < 1
  9.  
  10. pi = 4 * numpy.sum(inside_bool) / N
  11. print( pi )
  12.  
  13. x_in = x[inside_bool]
  14. y_in = y[inside_bool]
  15.  
  16. plt.figure(figsize=[5, 5])
  17. plt.scatter(x, y, s=1)
  18. plt.scatter(x_in, y_in, color='r', s=1)
  19. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement