Extract the main diagonal of a sparse matrix in scipy.sparse python

How to extract the main diagonal of a sparse matrix? The matrix is ​​created in scipy.sparse. I want the equivalent of np.diagonal (), but for a sparse matrix.

+7
python scipy sparse-matrix
source share
1 answer

The rare matrix has a diagonal method:

 M.diagonal() 

http://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csc_matrix.diagonal.html

The numpy chart is a little more powerful, allowing you to specify a diagonal diagonal

 MAdiagonal(2) 
+7
source share

All Articles