When you do a dot product between two vectors or matrices, the order matters. Matrix multiplication is not a commutative operation in general. In this case you’ve got two vectors of dimension 1 x m. You did Y^T \cdot log(A), so that is m x 1 dotted with 1 x m, so you get an m x m output, right? But you want a scalar value.
Here’s a thread which shows an example of why your method is incorrect and shows the way to understand the correct method.