Python在4维球体上的点的均匀分布 [英] Python Uniform distribution of points on 4 dimensional sphere
本文介绍了Python在4维球体上的点的均匀分布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在4维球体上均匀分布点.我知道这并不像选择3个角度并使用极坐标那样简单.
I need a uniform distribution of points on a 4 dimensional sphere. I know this is not as trivial as picking 3 angles and using polar coordinates.
我使用的3维尺寸
from random import random
u=random()
costheta = 2*u -1 #for distribution between -1 and 1
theta = acos(costheta)
phi = 2*pi*random
x=costheta
y=sin(theta)*cos(phi)
x=sin(theta)*sin(phi)
这给出了x,y和z的均匀分布.
This gives a uniform distribution of x, y and z.
如何获得4维的相似分布?
How can I obtain a similar distribution for 4 dimensions?
推荐答案
A standard way, though, perhaps not the fastest, is to use Muller's method to generate uniformly distributed points on an N-sphere:
import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.axes3d as axes3d
N = 600
dim = 3
norm = np.random.normal
normal_deviates = norm(size=(dim, N))
radius = np.sqrt((normal_deviates**2).sum(axis=0))
points = normal_deviates/radius
fig, ax = plt.subplots(subplot_kw=dict(projection='3d'))
ax.scatter(*points)
ax.set_aspect('equal')
plt.show()
只需将dim = 3
更改为dim = 4
即可在4个球体上生成点.
Simply change dim = 3
to dim = 4
to generate points on a 4-sphere.
这篇关于Python在4维球体上的点的均匀分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文