I have a sparse large matrix (linear dimension of 2*10^6) for which I want to calculate its trace.
Calculating it brute force takes 16 seconds to access each diagonal element (hence I could do it in a YEAR!). 
I was thinking of saving it to the disk using scipy.io.mmwrite and reading it with a c++ code which should be much faster. However I cannot find any package that could help me do that.
Any suggestions would be much appreciated!
Thanks.
The solution was as simple as: np.array(Mat.diagonal()).sum()
Thanks @hpaulj !
Calculating the trace of a large sparse matrix