numerically stable way to multiply log probability matrices in numpy

后端 未结 4 1189
逝去的感伤
逝去的感伤 2021-02-02 06:55

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

4条回答
  •  遇见更好的自我
    2021-02-02 07:58

    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.

提交回复
热议问题