vectorisation of gradient descent