2

Is there a general solution for this? You have to multiply them, but it is hard to implement.

For the 2 Dimensional case you can use the outer product of the two vector representing single normal distributions.

Moinuddin Quadri
  • 46,825
  • 13
  • 96
  • 126
Dániel Terbe
  • 105
  • 1
  • 10

2 Answers2

3

The general solution involves Cholesky decomposition of the variance/covariance matrix. Cholesky decomposition is available in Python via numpy.

Community
  • 1
  • 1
pjs
  • 18,696
  • 4
  • 27
  • 56
0

I found a possible solution and tested in 2d case. It seems good, but I'll test it on more cases:

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

2d case plot

Edit: I tested it in general cases too, it seems it is a correct solution! :)

Dániel Terbe
  • 105
  • 1
  • 10