Here's a recipe that can help:

1. Calculate $\log P(z_i = j, x_i)$ - do this by using the log of the expression for the pdf of normal directly. Let's call this number $b_{i,j}$.

2. Calculate $\log P(x_i) = \log(\sum_{j=1}^K P(z_i = j, x_i)) = log(\sum_{j=1}^K exp(b_{i,j}))$. This can be done by using the logsumexp function in numpy.

2. Calculate $\log P(z_i = j | x_i)$. By Bayes' law, this is equal to $\log P(z_i = j , x_i) - \log P(x_i)$, which uses quantities calculated in 1+2.

There will be no extra time - this exercise is short, with an extended deadline, and is non-mandatory (in the 5/6 sense). Note that the checker won't pick it up until Monday.