SciPy

scipy.sparse.spmatrix.diagonal

spmatrix.diagonal()[source]

Returns the main diagonal of the matrix