Solving multiple linear equations quickly
Solving Multiple Linear Equations with Numpy

Solving multiple linear equations with numpy

\begin{matrix} x+2y-z=4\\ 2x+y+z=-2\\ x+2y+z=2 \end{matrix}
In [1]:
import numpy as np
In [4]:
# coefficient matrix 
A = np.array([[1, 2, -1], [2, 1, 1], [1, 2, 1]])

# numbers on the right without variables
b = np.array([4, -2, 2])

# solve using np.linagl.solve()
np.linalg.solve(A, b)
Out[4]:
array([-1.66666667,  2.33333333, -1.        ])
Tags: numpy