def gradient_descent(cost, eta, n):
 w = np.random.uniform((-1), 1, 9)
 costs = []
 for j in xrange(n):
  c = cost(w)
  print 'Current cost: {0:.3f}'.format(c)
  costs.append(c)
  gradient = [partial(cost, k, w) for k in xrange(9)]
  w = np.array([(wt - (eta * d)) for (wt, d) in zip(w, gradient)])
 return (w, costs)

def gradient_descent ( cost , eta , n ) : w = np . random . uniform ( ( - 1 ) , 1 , 9 ) costs = [ ] for j in xrange ( n ) : c = cost ( w ) print 'Current cost: {0:.3f}' . format ( c ) costs . append ( c ) gradient = [ partial ( cost , k , w ) for k in xrange ( 9 ) ] w = np . array ( [ ( wt - ( eta * d ) ) for ( wt , d ) in zip ( w , gradient ) ] ) return ( w , costs )
perform n iterations of the gradient descent algorithm to minimize the cost function .