Consider this expression where $A$ and $B$ are matrices, $|i \rangle$ is a ket (column vector) and $\langle j |$ is a bra (row vector) : $$ A | i \rangle \langle j | B \tag1\label1 $$
Due to the general associative properties of the bra-ket notation, this can be interpreted as the inner product of 2 vectors: $$ \left( A | i \rangle \right) \left( \langle j | B \right) \tag2\label2 $$
But by regrouping the terms and considering that outer products can be given a matrix representation, \eqref{1} can also be interpreted as the product of 3 matrices:
$$ A (| i \rangle \langle j |) B \tag3\label3 $$
My confusion comes from the mismatch of the dimensions of expressions \eqref{2} and \eqref{3}. \eqref{2} yields a complex scalar, while \eqref{3} yields a matrix. If the associative property holds, I'd expect the dimensions not to depend on the grouping of the terms. Could somebody please shed some light where I am getting confused?