{ } Raw JSON

bundles / scipy 1.17.1 / scipy / sparse / _extract / tril

function

scipy.sparse._extract:tril

source: /scipy/sparse/_extract.py :46

Signature

def   tril ( A k = 0 format = None )

Summary

Return the lower triangular portion of a sparse array or matrix

Extended Summary

Returns the elements on or below 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 matrix

Matrix whose lower trianglar portion is desired.

k : integer : optional

The top-most diagonal of the lower triangle.

format : string

Sparse format of the result, e.g. format="csr", etc.

Returns

L : sparse matrix

Lower triangular portion of A in sparse format.

Examples

from scipy.sparse import csr_array, tril
A = csr_array([[1, 2, 0, 0, 3], [4, 5, 0, 6, 7], [0, 0, 8, 9, 0]],
              dtype='int32')
A.toarray()
tril(A).toarray()
tril(A).nnz
tril(A, k=1).toarray()
tril(A, k=-1).toarray()
tril(A, format='csc')

See also

triu

upper triangle in sparse format

Aliases

  • scipy.sparse.tril

Referenced by