update gradient descent code in Python