bundles / scipy 1.17.1 / scipy / sparse / _extract / triu
function
scipy.sparse._extract:triu
source: /scipy/sparse/_extract.py :113
Signature
def triu ( A , k = 0 , format = None ) Summary
Return the upper triangular portion of a sparse array or matrix
Extended Summary
Returns the elements on or above the k-th diagonal of A.
k = 0 corresponds to the main diagonal
k > 0 is above the main diagonal
k < 0 is below the main diagonal
Parameters
A: dense or sparse array or matrixMatrix whose upper trianglar portion is desired.
k: integer : optionalThe bottom-most diagonal of the upper triangle.
format: stringSparse format of the result, e.g. format="csr", etc.
Returns
L: sparse array or matrixUpper triangular portion of A in sparse format. Sparse array if A is a sparse array, otherwise matrix.
Examples
from scipy.sparse import csr_array, triu A = csr_array([[1, 2, 0, 0, 3], [4, 5, 0, 6, 7], [0, 0, 8, 9, 0]], dtype='int32') A.toarray() triu(A).toarray() triu(A).nnz triu(A, k=1).toarray() triu(A, k=-1).toarray()✓
triu(A, format='csc')
✗See also
- tril
lower triangle in sparse format
Aliases
-
scipy.sparse.triu