Skip to main content
`Ctrl`+`K`
scipy.sparse.linalg.

# is_sptriangular

scipy.sparse.linalg.is_sptriangular(A)

  Returns 2-tuple indicating lower/upper triangular structure for sparse `A`

  Checks for triangular structure in `A`. The result is summarized in two boolean values `lower` and `upper` to designate whether `A` is lower triangular or upper triangular respectively. Diagonal `A` will result in both being True. Non-triangular structure results in False for both.

  Only the sparse structure is used here. Values are not checked for zeros.

  This function will convert a copy of `A` to CSC format if it is not already CSR or CSC format. So it may be more efficient to convert it yourself if you have other uses for the CSR/CSC version.

  If `A` is not square, the portions outside the upper left square of the matrix do not affect its triangular structure. You probably want to work with the square portion of the matrix, though it is not requred here.

  Parameters:
    A SciPy sparse array or matrix

      A sparse matrix preferrably in CSR or CSC format.

  Returns:
    lower, upper 2-tuple of bool

      Added in version 1.15.0.

  Examples

      >>> import numpy as np
      >>> from scipy.sparse import csc_array, eye_array
      >>> from scipy.sparse.linalg import is_sptriangular
      >>> A = csc_array([[3, 0, 0], [1, -1, 0], [2, 0, 1]], dtype=float)
      >>> is_sptriangular(A)
      (True, False)
      >>> D = eye_array(3, format='csr')
      >>> is_sptriangular(D)
      (True, True)