Solve coupled linear equations
Numerical models and simulations
SciPy · Function
Solves the square-matrix system a @ x = b. Structure hints, batching, transpose solving, overwrite options, and finite-value checking are supported.
solve computes x for the linear system a @ x = b. It accepts one matrix and either one or multiple right-hand sides, while optional structure hints such as assume_a="sym" select a specialized solver; batch dimensions may also precede the core matrix dimensions.
scipy.linalg.solve(a, b, lower=False, overwrite_a=False, overwrite_b=False, check_finite=True, assume_a=None, transposed=False)| Name | Type | Description |
|---|---|---|
a | array_like, shape (…, N, N) | Square left-hand-side matrix or a batch of matrices. |
b | array_like, shape (…, N, NRHS) | Right-hand-side data or a batch of right-hand sides. |
lower | bool, default: False | Whether the referenced structured matrix uses its lower triangle; ignored for other structures. |
overwrite_a | bool, default: False | Permit overwriting a, potentially improving performance. |
overwrite_b | bool, default: False | Permit overwriting b, potentially improving performance. |
check_finite | bool, default: True | Check that input matrices contain only finite values. |
assume_a | str, optional | Known matrix structure, such as diagonal, tridiagonal, banded, sym, her, pos, or gen. |
transposed | bool, default: False | Solve using the transpose of a. |
x, an ndarray containing the solution, with shape (N, NRHS) or (…, N) depending on the right-hand side.
assume_a to select a solver specialized for known matrix structure.overwrite_a=True permits reuse of the matrix storage and may improve performance.transposed=True to solve against the transpose of a.check_finite=False can improve speed, but invalid values may cause crashes or non-termination.lower option has no effect unless the selected matrix structure is symmetric, Hermitian, or positive definite.transposed=True solves the ordinary transpose system, not the conjugate transpose system.import numpy as np
from scipy.linalg import solve
a = np.array([[3.0, 1.0], [1.0, 2.0]])
b = np.array([9.0, 8.0])
x = solve(a, b, assume_a="sym")
print(x) # [2. 3.]Solves a symmetric two-by-two system and prints the solution vector.
Numerical models and simulations
Many independent systems with compatible leading dimensions
Known symmetric, Hermitian, diagonal, banded, or triangular structure
scipy.linalg.solve solve?It finds x satisfying a @ x = b, where a must be square. The right-hand side can represent one or several systems.
Follow-up: How can performance improve for structured matrices? Pass the appropriate assume_a value, such as sym, her, pos, diagonal, or tridiagonal, so SciPy can choose a dedicated solver.
a, b, and the result support?a is a square matrix or batch of square matrices. b contains the matching right-hand side vector or matrix, and the result has the corresponding solution shape.
Follow-up: What does batching mean here? Additional dimensions may precede the core (N, N) matrix shape, allowing multiple systems to be supplied together.
check_finite?check_finite=True verifies that input matrices contain only finite numbers. Disabling it can be faster, but bad values can lead to serious runtime problems.
Follow-up: When is disabling the check reasonable? Only when finiteness is guaranteed by trusted upstream validation and the performance trade-off is worthwhile.
scipy.linalg.solve_triangularscipy.linalg.solve_bandedscipy.linalg.lstsqscipy.linalg.inv