I am implementing a variance-covariance matrix myself and I'm having some trouble understanding what is meant by the expectation this equation:
$ Cov(X, X) = E[(X - E(x))(X - E(x))']$
From what I understand, the expectation of a matrix of variables is the expectation of the columns of the matrix:
$ X = \left( \begin{array}{ccc} 1 & 4 & 7 \\ 2 & 5 & 8 \\ 3 & 6 & 9 \\ 4 & 3 & 2 \end{array} \right) $
$E(X) = \left(\begin{array}{ccc} 2.5 & 4.5 & 6.5 \end{array}\right)' $
I would expect the variance-covariance matrix to be a $3x3$ matrix but using this definition of expectation $(X - E(x))$ is a $4x3$ matrix, $(X - E(x))'$ is a $3x4$ matrix, $(X - E(x))(X - E(x))'$ is therefore a $3x3$ matrix but the the expectation of this is going to be a $3x1$ column vector using the above definition.
How is this outer expectation performed so the result is a $3x3$ matrix?