code: def apply_penalty(tensor_or_tensors, penalty, **kwargs):
      """
      Computes the total cost for applying a specified penalty
      to a tensor or group of tensors.
  
      Parameters
      ----------
      tensor_or_tensors : Theano tensor or list of tensors
      penalty : callable
      **kwargs
          keyword arguments passed to penalty.
  
      Returns
      -------
      Theano scalar
          a scalar expression for the total penalty cost
      """
      try:
          return sum(penalty(x, **kwargs) for x in tensor_or_tensors)
      except (TypeError, ValueError):
          return penalty(tensor_or_tensors, **kwargs)
  
file_path: Lasagne/lasagne/regularization.py
imports: import theano.tensor
  from .layers import Layer, get_all_params
label_desc: Use image node_id 3 for calling a global function with example usage: apply_penalty(tensor_or_tensors, penalty) and returns: sum, penalty