code: def gradient(self):
          
          functional = self
  
          if self.exponent == 1:
              class L1Gradient(Operator):
  
                  """The gradient operator of this functional."""
  
                  def __init__(self):
                      """Initialize a new instance."""
                      super(L1Gradient, self).__init__(
                          functional.domain, functional.domain, linear=False)
  
                  def _call(self, x):
                      """Apply the gradient operator to the given point."""
                      return x.ufuncs.sign()
  
                  def derivative(self, x):
                      """Derivative is a.e. zero."""
                      return ZeroOperator(self.domain)
  
              return L1Gradient()
  
          elif self.exponent == 2:
              class L2Gradient(Operator):
  
                  """The gradient operator of this functional."""
  
                  def __init__(self):
                      """Initialize a new instance."""
                      super(L2Gradient, self).__init__(
                          functional.domain, functional.domain, linear=False)
  
                  def _call(self, x):
                      """Apply the gradient operator to the given point.
  
                      The gradient is not defined in 0.
                      """
                      norm_of_x = x.norm()
                      if norm_of_x == 0:
                          return self.domain.zero()
                      else:
                          return x / norm_of_x
  
              return L2Gradient()
  
          else:
              raise NotImplementedError('`gradient` only implemented for p=1 '
                                        'and p=2')
docs: Gradient operator of the functional.
  
          The functional is not differentiable in ``x=0``. However, when
          evaluating the gradient operator in this point it will return 0.