def normal_nd(*priors):
# Trivial case
if len(priors) == 1:
return priors
# General case
shape = []
for item in priors:
shape.append(len(item))
n = np.ones(shape)
for idx, _ in np.ndenumerate(n):
for ax, element in enumerate(idx):
n[idx] *= priors[ax][element]
return n
我找到了一个可能的解决方案,并在二维案例中进行了测试。看起来不错,但我会在更多情况下进行测试:
编辑: 我也在一般情况下进行了测试,似乎这是一个正确的解决方案!:)
通解涉及Cholesky decomposition of the variance/covariance matrix。Cholesky分解在Python中通过numpy提供。在
相关问题 更多 >
编程相关推荐