三维高斯分布 抽样python
时间: 2023-10-30 14:06:46 浏览: 100
三维高斯分布抽样的Python代码如下:
```python
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
def multivariate_gaussian_sampling(mean, cov, num_samples):
samples = np.random.multivariate_normal(mean, cov, num_samples)
return samples
mean = np.array([0, 0, 0]) # 均值向量
cov = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) # 协方差矩阵
num_samples = 1000 # 抽样数量
samples = multivariate_gaussian_sampling(mean, cov, num_samples)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(samples[:, 0], samples[:, 1], samples[:, 2])
plt.show()
```
阅读全文