I need to take the matrix product of two NumPy matrices (or other 2d arrays) containing log probabilities. The naive way np.log(np.dot(np.exp(a), np.exp(b))) is not
np.log(np.dot(np.exp(a), np.exp(b)))
You are accessing columns of res and b, which has poor locality of reference. One thing to try is to store these in column-major order.
res
b