scipy.sparse.triu
scipy.sparse.triu(A, k=0, format=None)
以稀疏格式返回矩阵的上三角部分。
返回矩阵A的第k个对角线上或上方的元素。
- k = 0对应于主对角线
- k> 0在主对角线上方
- k <0在主对角线以下
参数:
A:dense or sparse matrix | 需要其上三角部分的矩阵。 |
---|---|
k:integer | 上三角的最底对角线。 |
format:string | 结果的稀疏格式,如format=“ csr”,等等。 |
返回:
L:sparse matrix | A的上三角部分为稀疏格式。 |
---|
官网例子
>>> from scipy.sparse import csr_matrix, triu
>>> A = csr_matrix([[1, 2, 0, 0, 3], [4, 5, 0, 6, 7]