Representing projection operator in terms of orthonormal basis The question given is :
Let $P: V \rightarrow V$ be a projection operator, i.e., $P^{2}=P .$ If $V$ is finite dimensional, then show that $\operatorname{tr}(P)$ is the dimension of the subspace being projected onto.
The solution is:

*

*Let $P$ be an orthogonal projection operator to $M$ dimensional subspace $V$


*Let $b_{1}, \ldots, b_{M}$ be an orthonormal basis for $V .$ Then
$$
\begin{aligned}
P=\sum_{m=1}^{M} b_{m} b_{m}^{\prime} & \\
\qquad \begin{aligned}
\operatorname{Trace}(P) &=\operatorname{Trace}\left(\sum_{m=1}^{M} b_{m} b_{m}^{\prime}\right) \\
&=\sum_{m=1}^{M} \operatorname{Trace}\left(b_{m} b_{m}^{\prime}\right)=\sum_{m=1}^{M} \operatorname{Trace}\left(b_{m}^{\prime} b_{m}\right) \\
&=\sum_{m=1}^{M} \operatorname{Trace}(1)=\sum_{m=1}^{M} 1=M
\end{aligned}
\end{aligned}
$$
Can anyone explain the first step of the proof, i.e. how the projection operator is represented as $P=\sum_{m=1}^{M} b_{m} b_{m}^{\prime}$ where $b_{1}, \ldots, b_{M}$ be an orthonormal basis for $V .$

If $P$ is also assumed to be symmetric ($P^T=P$), and $b_1,\dots,b_M$ is an orthonormal basis of the image of $P$, then indeed one has $P=\sum_ib_ib_i^T=:B$:
Note that since $P$ is symmetric, its eigenspaces (i.e. the kernel and the range) are orthogonal.
Furthermore, it's easy to verify that if $v\in{\rm im}(P)={\rm span}(b_1,\dots,b_M)$, then $Bv=v$, and that if $v\perp{\rm im}(P)$, then $Bv=0$, and these properties characterize $P$.
Nevertheless, the statement is true for general projections as well:
If $P^2=P$, we still have $V={\rm im}(P)\oplus\ker(P)$, though these subspaces might not be orthogonal to each other in the general case.
Choosing bases $v_1,\dots,v_M$ in ${\rm im}(P)$ and $u_1,\dots,u_K$ in $\ker(P)$, we find that the matrix of $P$ in basis $v_1,\dots,v_M,u_1,\dots,u_K$ is diagonal with $M$ entries of $1$ and $K$ entries of $0$, because $Pv_i=v_i$ and $Pu_i=0$.
Consequently, ${\rm tr}(P)=M$.
