title: Understanding Gradient Descent for Multivariate Linear Regression python implementation
body: <p>It seems that the following code finds the gradient descent correctly:</p>
  
  <pre><code>def gradientDescent(x, y, theta, alpha, m, numIterations):
      xTrans = x.transpose()
      for i in range(0, numIterations):
          hypothesis = np.dot(x, theta)
          loss = hypothesis - y 
          cost = np.sum(loss ** 2) / (2 * m)
          print("Iteration %d | Cost: %f" % (i, cost))
          # avg gradient per example
          gradient = np.dot(xTrans, loss) / m 
          # update
          theta = theta - alpha * gradient
      return theta
  </code></pre>
  
  <p>Now suppose we have the following sample data:</p>
  
  <p><a href="https://i.stack.imgur.com/K7Cx0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/K7Cx0.png" alt="enter image description here"></a></p>
  
  <p>For the 1st row of sample data, we will have:
  <code>x = [2104, 5, 1, 45]</code>, <code>theta = [1,1,1,1]</code>, <code>y = 460</code>.
  However, we are nowhere specifying in the lines :</p>
  
  <pre><code>hypothesis = np.dot(x, theta)
  loss = hypothesis - y
  </code></pre>
  
  <p>which row of the sample data to consider. Then how come this code is working fine ?</p>