PS: if this is rate limiting, you can try using NumExpr here.  `np.exp` could be pretty slow...