Skip to main content
 首页 » 编程设计

python之从python中的矩阵正态分布中随机抽取样本

2025年05月04日13yjmyzz

有没有办法使用 python 从矩阵正态分布 ( https://en.wikipedia.org/wiki/Matrix_normal_distribution#Drawing_values_from_the_distribution ) 中随机抽取样本? Numpy 具有从一维正态分布和多元正态分布中绘制的功能,但我在矩阵正态分布上找不到任何东西。谢谢。

请您参考如下方法:

从您链接的维基百科页面:

The matrix normal is related to the multivariate normal distribution in the following way:

\mathbf{X} \sim \mathcal{MN}_{n\times p}(\mathbf{M}, \mathbf{U}, \mathbf{V}),

if and only if

\mathrm{vec}(\mathbf{X}) \sim \mathcal{N}_{np}(\mathrm{vec}(\mathbf{M}), \mathbf{V} \otimes \mathbf{U})

翻译成numpy,应该是

numpy.random.multivariate_normal(M.ravel(), np.kron(V, U)).reshape(M.shape)