bundles / scipy 1.17.1 / scipy / sparse / linalg / _dsolve / linsolve / spsolve_triangular
function
scipy.sparse.linalg._dsolve.linsolve:spsolve_triangular
Signature
def spsolve_triangular ( A , b , lower = True , overwrite_A = False , overwrite_b = False , unit_diagonal = False ) Summary
Solve the equation A x = b for x, assuming A is a triangular matrix.
Parameters
A: (M, M) sparse array or matrixA sparse square triangular matrix. Should be in CSR or CSC format.
b: (M,) or (M, N) array_likeRight-hand side matrix in
A x = blower: bool, optionalWhether
Ais a lower or upper triangular matrix. Default is lower triangular matrix.overwrite_A: bool, optionalAllow changing
A. Enabling gives a performance gain. Default is False.overwrite_b: bool, optionalAllow overwriting data in
b. Enabling gives a performance gain. Default is False. Ifoverwrite_bis True, it should be ensured thatbhas an appropriate dtype to be able to store the result.unit_diagonal: bool, optionalIf True, diagonal elements of
aare assumed to be 1.
Returns
x: (M,) or (M, N) ndarraySolution to the system
A x = b. Shape of return matches shape ofb.
Raises
: LinAlgErrorIf
Ais singular or not triangular.: ValueErrorIf shape of
Aor shape ofbdo not match the requirements.
Notes
Examples
import numpy as np from scipy.sparse import csc_array from scipy.sparse.linalg import spsolve_triangular A = csc_array([[3, 0, 0], [1, -1, 0], [2, 0, 1]], dtype=float) B = np.array([[2, 0], [-1, 0], [2, 0]], dtype=float) x = spsolve_triangular(A, B) np.allclose(A.dot(x), B)✓
Aliases
-
scipy.sparse.linalg.spsolve_triangular