python绘制一个单位球面,Python在4维球面上的点的均匀分布

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.

In 3 dimensions I use

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)

This gives a uniform distribution of x, y and z.

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()

6FZJN.png

Simply change dim = 3 to dim = 4 to generate points on a 4-sphere.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值