diagonal
scipy.sparse.csr_matrix.
- csr_matrix.diagonal(k=0)
Returns the kth diagonal of the array/matrix.
- Parameters:
- k : int, optional
Which diagonal to get, corresponding to elements a[i, i+k]. Default: 0 (the main diagonal).
Returns the kth diagonal of the array/matrix.
Which diagonal to get, corresponding to elements a[i, i+k]. Default: 0 (the main diagonal).
Added in version 1.0.
The specified diagonal of the array/matrix.
>>> from scipy.sparse import csr_array
>>> A = csr_array([[1, 2, 0], [0, 0, 3], [4, 0, 5]])
>>> A.diagonal()
array([1, 0, 5])
>>> A.diagonal(k=1)
array([2, 3])