Completed gradient descent in Python