def rosen_hess(x):
 x = atleast_1d(x)
 H = (numpy.diag(((-400) * x[:(-1)]), 1) - numpy.diag((400 * x[:(-1)]), (-1)))
 diagonal = numpy.zeros(len(x), dtype=x.dtype)
 diagonal[0] = (((1200 * (x[0] ** 2)) - (400 * x[1])) + 2)
 diagonal[(-1)] = 200
 diagonal[1:(-1)] = ((202 + (1200 * (x[1:(-1)] ** 2))) - (400 * x[2:]))
 H = (H + numpy.diag(diagonal))
 return H

def rosen_hess ( x ) : x = atleast_1d ( x ) H = ( numpy . diag ( ( ( - 400 ) * x [ : ( - 1 ) ] ) , 1 ) - numpy . diag ( ( 400 * x [ : ( - 1 ) ] ) , ( - 1 ) ) ) diagonal = numpy . zeros ( len ( x ) , dtype = x . dtype ) diagonal [ 0 ] = ( ( ( 1200 * ( x [ 0 ] ** 2 ) ) - ( 400 * x [ 1 ] ) ) + 2 ) diagonal [ ( - 1 ) ] = 200 diagonal [ 1 : ( - 1 ) ] = ( ( 202 + ( 1200 * ( x [ 1 : ( - 1 ) ] ** 2 ) ) ) - ( 400 * x [ 2 : ] ) ) H = ( H + numpy . diag ( diagonal ) ) return H
the hessian matrix of the rosenbrock function .