scipy.sparse.lil_matrix.trace#

lil_matrix.trace(offset=0)[source]#

Returns the sum along diagonals of the sparse array.

Parameters:
offsetint, optional

Which diagonal to get, corresponding to elements a[i, i+offset]. Default: 0 (the main diagonal).