def logdotexp(A, B):
    max_A = np.max(A)
max_B = np.max(B)
C = np.dot(np.exp(A - max_A), np.exp(B - max_B))
np.log(C, out=C)
C += max_A + max_B
return C
numerically stable way to multiply log probability matrices in numpy