Generate random points on 10-dimensional unit sphere

前端 未结 2 1362
天涯浪人
天涯浪人 2021-01-15 03:23

I need to generate a vector sampled uniformly with 10 directions (a collection of 10 random numbers) which lies over a unit sphere. So, the sum of the squares of the 10 valu

相关标签:
2条回答
  • 2021-01-15 04:03

    As @Andrex suggested, here is the right solution:

    import numpy as np
    import math
    
    s = np.random.normal(0, 1, 10)
    
    norm=math.sqrt(sum(s*s))
    result=s/norm
    

    where result is the answer. You can evaluate the result:

    sum([x*x for x in result])
    1.0
    
    0 讨论(0)
  • 2021-01-15 04:17

    There is a math theorem saying that if X = (X1,...,XN) is a vector with Xi the standard normal distribution, then X/NORM(X) is uniform in the unit sphere, where NORM is the euclidean norm. So you have to sample 10 points from a standard normal distribution (using numpy?) and then normalize the result.

    0 讨论(0)
提交回复
热议问题