scipy.sparse
dok_matrix.
diagonal
Returns the main diagonal of the matrix
scipy.sparse.dok_matrix.count_nonzero
scipy.sparse.dok_matrix.dot