title: Solve overdetermined system with QR decomposition in Python
body: <p>I'm trying to solve an overdetermined system with QR decomposition and linalg.solve but the error I get is</p>
  
  <p><em>LinAlgError: Last 2 dimensions of the array must be square</em>.</p>
  
  <p>This happens when the R array is not square, right? The code looks like this</p>
  
  <pre><code>import numpy as np
  import math as ma
  
  A = np.random.rand(2,3)
  b = np.random.rand(2,1) 
  Q, R = np.linalg.qr(A)
  Qb = np.matmul(Q.T,b)
  x_qr = np.linalg.solve(R,Qb)
  </code></pre>
  
  <p>Is there a way to write this in a more efficient way for arbitrary A dimensions? If not, how do I make this code snippet work?</p>