# Matrix Multiplication: Both ways okay?

Say I have two matrices $A$ and $B$ where $A$ has dimensions of $1 \times 2$ ($1$ row, $2$ columns) and $B$ has dimensions of $2 \times 3$ ($2$ rows, $3$ columns)

When you multiply these like so $(A \cdot B)$ you get a $1 \times 3$ matrix.

It was my understanding that this was correct, but I was advised by a grader that I should have done it like so, where $A$ as a $2 \times 1$ matrix and $B$ as a $3 \times 2$ matrix

Then, when multiplying do it like so $(B \cdot A)$ which gives a $3 \times 1$ matrix.

Both approaches give the same three numbers, except one is a $3 \times 1$ matrix and the other a $1 \times 3$.

It was my belief that both were correct and which one you chose is arbitrary. Have I misunderstood?

Additionally, the matrices were intended to reflect the weights on a graph in a figure. Should the presentation of such a graph effect how I decide to represent their dimensions as matrices? Again, I didn't think this was the case...

• Matrix multiplication is not commutative. – Zain Patel Jul 5 '15 at 13:19

In general, matrix multiplication is not commutative, so $$A\cdot B \neq B \cdot A$$ this means that you cannot arbitrarily choose one product over another. You must choose the right product given the context of the situation, even if both products give the same numbers.
$$(AB)^T=B^TA^T$$
I do not know what you did for $B\cdot A$, but it was no matrix multiplication: $$(BA)_{ik}=\sum_{j=1}^n b_{ij} a_{jk}$$ but $B$'s column index $j$ would range from $1$ to $3$ while $A$'s row index $j$ can only take the value $1$, so this will not work as common ranges are needed.