You have to be careful with the dot products and transposes there. Here’s a thread which discusses the difference between y^T \cdot x and y \cdot x^T for row vectors.
A hint is that if you do the dot product correctly, there is no need for the np.sum
call there. See that other thread for a more detailed explanation.