This is documentation for an old release of SciPy (version 1.8.1). Read this page in the documentation of the latest stable release (version 1.15.1).

scipy.sparse.csr_matrix.trace#

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

Returns the sum along diagonals of the sparse matrix.

Parameters
offsetint, optional

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