TITLE: Why is the expectation of a trace equal to the trace of the expectation?
QUESTION [5 upvotes]: Some textbooks use the property $$\mathbb{E}\left[\operatorname{tr}\left(X\right)\right]=\operatorname{tr}\left(\mathbb{E}\left[X\right]\right)$$
But why? I would really appreciate it if someone could prove this.

REPLY [5 votes]: I am assuming that $X$ is a random matrix, with finite dimensions. Then
$$
\textrm{tr}\ X=\sum_i X_{ii}.
$$
Hence, the claim follows by linearity of expectation, since
$$
\mathbb E(\textrm{tr}\ X)=\mathbb E\sum_i X_{ii}=\sum_i \mathbb E X_{ii}=\sum_i (\mathbb E X)_{ii}=\textrm{tr}\ (\mathbb EX).
$$