code: def gradient(self):
          
          functional = self
          c = self.scale
  
          class RosenbrockGradient(Operator):
  
              """The gradient operator of the Rosenbrock functional."""
  
              def __init__(self):
                  """Initialize a new instance."""
                  super(RosenbrockGradient, self).__init__(
                      functional.domain, functional.domain, linear=False)
  
              def _call(self, x, out):
                  """Apply the gradient operator to the given point."""
                  for i in range(1, self.domain.size - 1):
                      out[i] = (2 * c * (x[i] - x[i - 1]**2) -
                                4 * c * (x[i + 1] - x[i]**2) * x[i] -
                                2 * (1 - x[i]))
                  out[0] = (-4 * c * (x[1] - x[0] ** 2) * x[0] +
                            2 * (x[0] - 1))
                  out[-1] = 2 * c * (x[-1] - x[-2] ** 2)
  
              def derivative(self, x):
                  """The derivative of the gradient.
  
                  This is also known as the Hessian.
                  """
                  # TODO: Implement optimized version of this that does not need
                  # a matrix.
                  shape = (functional.domain.size, functional.domain.size)
                  matrix = np.zeros(shape)
  
                  # Straightforward computation
                  for i in range(0, self.domain.size - 1):
                      matrix[i, i] = (2 * c + 2 + 12 * c * x[i] ** 2 -
                                      4 * c * x[i + 1])
                      matrix[i + 1, i] = -4 * c * x[i]
                      matrix[i, i + 1] = -4 * c * x[i]
                  matrix[-1, -1] = 2 * c
                  matrix[0, 0] = 2 + 12 * c * x[0] ** 2 - 4 * c * x[1]
                  return MatrixOperator(matrix, self.domain, self.range)
  
          return RosenbrockGradient()
docs: Gradient operator of the Rosenbrock functional.