Why the second term is transposed, but not the first one? I am not very good at maths. I just have this silly question. Why do I have to transpose the second term in expectation?
I mean why $Var(X) = E[(x−μ)(x−μ)^T)]$ and not this $E[(x−μ)^T(x−μ))]$ ?
 A: When you multiply matrices, the adjacent dimensions need to match, so you can multiply the (n, k) matrix by (k, m) matrix, or (m, k) by (k, n), but not any other way around. Where you would see the transpose symbol it depends on if the data is stored row-wise or column-wise. If you take something like a dot product of row vectors, you would transpose the second element so you multiply (1, n) by (n, 1), but if the data had the initial shape of (n, 1), you would do the opposite.
A: For any column vector $x$ (eg $x \in \mathbb R^{n \times 1}$)

*

*$x^Tx$ is (a 1x1 matrix and thus 'is isomorphic to' (*)) a scalar.


*$xx^T$ is a matrix. (and if it's 1x1, then it could be treated as a scalar similarly.)
(*) in your case 'is isomorphic to' just means 'can be treated as'
A: If you use the convention that $(\boldsymbol{x} - \boldsymbol{\mu})$ is a column vector, i.e.  $(\boldsymbol{x} - \boldsymbol{\mu}) = \begin{bmatrix}
           x_{1} - \mu_1\\
           x_{2} - \mu_2\\
           \vdots \\
           x_{m}- \mu_m
         \end{bmatrix}$, then $(\boldsymbol{x} - \boldsymbol{\mu})^T$ is a row vector, i.e $(\boldsymbol{x} - \boldsymbol{\mu})^T= [x_{1} - \mu_1, x_{2} - \mu_2,\dots ,x_{m} - \mu_m]$.
The product of a column vector and a row vector forms a matrix with the corresponding pairwise products as entries. The product of a row vector and a column vector (the dot product) results in the sum of the pairwise products.
Since your $Var(X)$ is a variance-covariance matrix, you need to have the product of a column vector and a row vector, i.e. $(\boldsymbol{x}-\boldsymbol{\mu})(\boldsymbol{x}-\boldsymbol{\mu})^T$.
