Solution (source code)

= Solution

If the <idempotent matrix> $M$ is invertible, multiply $M^2=M$ on the left by its <matrix inverse>:
$$
M^{-1}M^2=M^{-1}M\quad\Longrightarrow\quad\boxed{M=I.}
$$
Thus a nonidentity <idempotent matrix> must be singular; the identity itself is both invertible and idempotent.