Generate random points on 10-dimensional unit sphere

前端 未结 2 1365
天涯浪人
天涯浪人 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
    

提交回复
热议问题