# Why is the expectation of a trace equal to the trace of the expectation?

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.

• Taking the trace is a linear operation (it's essentially a sum). So you can use linearity of expectations. – Riccardo Sven Risuleo Jun 20 '19 at 4:53

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).$$