jeudi 15 août 2019

Random point from a multidimensional ball in Python

I would like to draw points from a n-dimensional ball.

I know how to do it for 2D ball, but it is tricky for more dimensions.

Is there any built-in function to do it? If not, what is the simplest effective implementation?

My solution for 2D case

phi = 2.0 * 180.0 * rand.random()
radius = math.sqrt(rand.random()) * 0.5
point = [0.5 + radius * math.cos(phi), 0.5 + radius * math.sin(phi)]




Aucun commentaire:

Enregistrer un commentaire