如何从 Python 中的 Wishart 分布中抽样

How to sample from a Wishart Distribution in Python

我需要从 Python 中的 Wishart 分布生成随机样本。有没有简单的方法可以做到这一点?

scipy 有一个 wishart 包:

import numpy as np
from scipy.stats import wishart

x = np.linspace(1e-5, 8, 100) # make an array
for y in x:
    z = wishart.rvs(1, scale=y)
    print(z)

输出:

4.59465858669e-06
0.00403122342709
0.0268879506122
0.0100029090879
0.129477863995
0.372787021348
....

wishart.rvs 是随机变量抽样的 wishart 函数。