That was all explained and demonstrated on the thread that I linked earlier. If you missed that the first time around, it is worth a look.
But it fundamentally comes down to understanding what the operations mean. It will be clear why y^T \cdot log(a) is not the same thing as y \cdot log(a)^T if you examine the examples given on that thread.