On this page
numpy.linalg.solve
numpy.linalg.solve(a, b)[source]- 
    
Solve a linear matrix equation, or system of linear scalar equations.
Computes the “exact” solution,
x, of the well-determined, i.e., full rank, linear matrix equationax = b.Parameters: - 
           
a : (…, M, M) array_like - 
           
Coefficient matrix.
 - 
           
b : {(…, M,), (…, M, K)}, array_like - 
           
Ordinate or “dependent variable” values.
 
Returns: - 
           
x : {(…, M,), (…, M, K)} ndarray - 
           
Solution to the system a x = b. Returned shape is identical to
b. 
Raises: - LinAlgError
 - 
           
If
ais singular or not square. 
Notes
New in version 1.8.0.
Broadcasting rules apply, see the
numpy.linalgdocumentation for details.The solutions are computed using LAPACK routine _gesv
amust be square and of full-rank, i.e., all rows (or, equivalently, columns) must be linearly independent; if either is not true, uselstsqfor the least-squares best “solution” of the system/equation.References
[1] G. Strang, Linear Algebra and Its Applications, 2nd Ed., Orlando, FL, Academic Press, Inc., 1980, pg. 22. Examples
Solve the system of equations
3 * x0 + x1 = 9andx0 + 2 * x1 = 8:>>> a = np.array([[3,1], [1,2]]) >>> b = np.array([9,8]) >>> x = np.linalg.solve(a, b) >>> x array([ 2., 3.])Check that the solution is correct:
>>> np.allclose(np.dot(a, x), b) True - 
           
 
© 2005–2019 NumPy Developers
Licensed under the 3-clause BSD License.
 https://docs.scipy.org/doc/numpy-1.16.1/reference/generated/numpy.linalg.solve.html