Skip to content

Instantly share code, notes, and snippets.

@pervognsen
Last active January 19, 2019 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pervognsen/0c1db0cf60bdb8d272cfab95634c1f32 to your computer and use it in GitHub Desktop.
Save pervognsen/0c1db0cf60bdb8d272cfab95634c1f32 to your computer and use it in GitHub Desktop.
def random_sphere_point(n):
# Any isotropic distribution would do, but isotropic multivariate normals are just a product of univariate normals.
x = np.random.randn(n)
return x / np.linalg.norm(x)
def random_ball_point(n):
# The volume cdf scales as r^n, hence the inverse cdf scales as r^(1/n).
return random_sphere_point(n) * np.random.random()**(1/n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment