In the book Quantum computation and quantum information, it says to evaluate $tr(A|\psi\rangle\langle\psi|)$ using Gram-Schmidt procedure to extend $|\psi\rangle$ to an orthonormal basis $|i\rangle$ which includes $|\psi\rangle$ as the first element. Then:
$$tr(A|\psi\rangle\langle\psi|)=\sum_i\langle i|A|\psi\rangle\langle\psi|i\rangle\tag{2.60}$$ $$=\langle\psi|A|\psi\rangle\tag{2.61}$$
I understood that equation 2.61 that uses the special basis $|i\rangle$ described. But in equation 2.60, how $\sum_i\langle i|M|i\rangle$ is correlated to $tr(M)$ ? Can you help me with a more detailed description of it ?