bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / linalg / solve
_ArrayFunctionDispatcher
numpy.linalg:solve
source: build-install/usr/lib/python3.14/site-packages/numpy/linalg/_linalg.py :363
Signature
def solve ( a , b ) Summary
Solve a linear matrix equation, or system of linear scalar equations.
Extended Summary
Computes the "exact" solution, x, of the well-determined, i.e., full rank, linear matrix equation ax = b.
Parameters
a: (..., M, M) array_likeCoefficient matrix.
b: {(M,), (..., M, K)}, array_likeOrdinate or "dependent variable" values.
Returns
x: {(..., M,), (..., M, K)} ndarraySolution to the system a x = b. Returned shape is (..., M) if b is shape (M,) and (..., M, K) if b is (..., M, K), where the "..." part is broadcasted between a and b.
Raises
: LinAlgErrorIf
ais singular or not square.
Notes
Broadcasting rules apply, see the numpy.linalg documentation for details.
The solutions are computed using LAPACK routine _gesv.
a must be square and of full-rank, i.e., all rows (or, equivalently, columns) must be linearly independent; if either is not true, use lstsq for the least-squares best "solution" of the system/equation.
Examples
Solve the system of equations: ``x0 + 2 * x1 = 1`` and ``3 * x0 + 5 * x1 = 2``:import numpy as np a = np.array([[1, 2], [3, 5]]) b = np.array([1, 2]) x = np.linalg.solve(a, b) x✓
np.allclose(np.dot(a, x), b)
✓See also
- scipy.linalg.solve
Similar function in SciPy.
Aliases
-
numpy.linalg.solve