I was asked to find the trace of $(A \in M_{n \times n})$, the matrix that can be written in the form:$$A=\frac{1}{n} \sum_{r, \, q \, = \, 1}^n (-1)^{r+q}|r \rangle \langle q| \quad ,$$ where {$|r \rangle$} is an orthonormal basis. I know that $(\langle r |q \rangle =\delta_{r, \, q})$ but I don't know what truly means $(|r \rangle \langle q|)$! In particular, I know the completeness relation: $$I=\sum_{j=1}^{n} |e_j \rangle \langle e_j| \quad ,$$ where is again an orthonormal basis; but, I know also that not every basis has that property.. Instead, it seems the case; in fact the solution gives me: $$\text{tr}(A)=\frac{1}{n} \sum_{r \, = \, 1}^n (-1)^{r+r}|r \rangle \langle r| = 1$$ Aside the abuse of notation, I think that the right solution should be: $$\require{cancel}\text{tr}(A)=\text{tr$\left(\frac{1}{n} \sum_{r \, = \, 1}^n (-1)^{r+r}|r \rangle \langle r|\right)$}=\frac{1}{n} \, \text{tr$\left(\sum_{r \, = \, 1}^n \cancel{(-1)^{2r}}|r \rangle \langle r|\right)$} = \frac{1}{n} \, \text{tr$\left(I\right)$}=\frac{1}{\cancel{n}}\cdot \cancel{n}=1$$ at this point what is really unclear to me is the step: $$\left[A=\frac{1}{n} \sum_{r, \, q \, = \, 1}^n (-1)^{r+q}|r \rangle \langle q|\right] \longmapsto \left[ \text{tr}(A)= \text{tr$\left(\frac{1}{n}\sum_{r \, = \, 1}^n |r \rangle \langle r|\right)$} \right]$$ where the second sum has gone? (how can this step be legitimate?)
Note: I already have been able to show that such a matrix is idempotent $(A^2 = A)$.