al of the upper triangle. format : string Sparse format of the result, e.g. format="csr", etc. Returns ------- L : sparse array or matrix Upper triangular portion of A in sparse format. Sparse array if A is a sparse array, otherwise matrix. See Also -------- tril : lower triangle in sparse format 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() array([[1, 2, 0, 0, 3], [4, 5, 0, 6, 7], [0, 0, 8, 9, 0]], dtype=int32) >>> triu(A).toarray() array([[1, 2, 0, 0, 3], [0, 5, 0, 6, 7], [0, 0, 8, 9, 0]], dtype=int32) >>> triu(A).nnz 8 >>> triu(A, k=1).toarray() array([[0, 2, 0, 0, 3], [0, 0, 0, 6, 7], [0, 0, 0, 9, 0]], dtype=int32) >>> triu(A, k=-1).toarray() array([[1, 2, 0, 0, 3], [4, 5, 0, 6, 7], [0, 0, 8, 9, 0]], dtype=int32) >>> triu(A, format='csc') Fr