title: Solving linear equations in Python (not working using linalg.solve)
body: <p>Probably this is a very beginner question. I am new to python and such operation. But would appreciate any help.
  I am trying to solve a system of linear equations in Python, using numpy linalg.</p>
  
  <p>x+y+z = 2 </p>
  
  <p>2x-6y-z=-1 </p>
  
  <p>3x-2z=8</p>
  
  <p>I tried to use linalg.solve() function </p>
  
  <pre><code>a = np.array([[1,2,3],[1,-6,0],[1,-1,-2]])
  b = np.array([2,-1,8])
  try:
      x1 = linalg.solve(a,b)
  except LinAlgError:
      x1 = linalg.lstsq(a,b)[0]
  print(x1)
  print(np.dot(a,x1) == b)
  </code></pre>
  
  <p>Here is the output </p>
  
  <pre><code>[ 5.38709677  1.06451613 -1.83870968]
  [ True  True  True]
  </code></pre>
  
  <p>However, this doesn't work if we put these received values instead x,y,z in equations.</p>
  
  <p>I tried another approach</p>
  
  <pre><code>x = np.dot(np.linalg.inv(a), b)
  print(x)
  print(np.dot(a,x) == b)
  </code></pre>
  
  <p>I received the same output as before:</p>
  
  <pre><code> [ 5.38709677  1.06451613 -1.83870968]
  </code></pre>
  
  <p>This method only worked if we change the places of <code>b</code> and <code>np.linalg.inv(a)</code>. Now it gives correct output.</p>
  
  <pre><code>x = np.dot(b, np.linalg.inv(a))
  print(x)
  print(np.dot(x,a) == b)
  </code></pre>
  
  <p>It works in equations </p>
  
  <pre><code>[ 2.  1. -1.]
  </code></pre>
  
  <p>So, here is the question. 
  Could anyone please explain why cannot I get [ 2.  1. -1.] using <code>linalg.solve</code>?</p>