the line
tmptheta = theta
should be updated to
tmptheta = np.copy(theta) // create a deep copy of theta instead of a new reference!
Otherwise the below statement will update theta also while the tmptheta is being updated (as both are references to same object!). theta should NOT change during an iteration of gradient descent!
tmptheta[j] = theta[j] - (alpha/m)*np.sum((h(theta,X) - y)*np.array(X[:,j]).reshape(m,1))
the line
tmptheta = thetashould be updated to
tmptheta = np.copy(theta)// create a deep copy of theta instead of a new reference!Otherwise the below statement will update theta also while the tmptheta is being updated (as both are references to same object!). theta should NOT change during an iteration of gradient descent!
tmptheta[j] = theta[j] - (alpha/m)*np.sum((h(theta,X) - y)*np.array(X[:,j]).reshape(m,1))