parameters: (x: torch.tensor, scale='l2')
return_statement: return x
docstring: Apply global contrast normalization to tensor, i.e. subtract mean across features (pixels) and normalize by scale,
      which is either the standard deviation, L1- or L2-norm across features (pixels).
      Note this is a *per sample* normalization globally across features (and not across the dataset).
docstring_summary: Apply global contrast normalization to tensor, i.e. subtract mean across features (pixels) and normalize by scale,
      which is either the standard deviation, L1- or L2-norm across features (pixels).
      Note this is a *per sample* normalization globally across features (and not across the dataset).
docstring_tokens: Apply global contrast normalization to tensor i . e . subtract mean across features ( pixels ) and normalize by scale which is either the standard deviation L1 - or L2 - norm across features ( pixels ) . Note this is a * per sample * normalization globally across features ( and not across the dataset ) .
function: def global_contrast_normalization(x: torch.tensor, scale='l2'):
      """
      Apply global contrast normalization to tensor, i.e. subtract mean across features (pixels) and normalize by scale,
      which is either the standard deviation, L1- or L2-norm across features (pixels).
      Note this is a *per sample* normalization globally across features (and not across the dataset).
      """
  
      assert scale in ('l1', 'l2')
  
      n_features = int(np.prod(x.shape))
  
      mean = torch.mean(x)  # mean over all features (pixels) per sample
      x -= mean
  
      if scale == 'l1':
          x_scale = torch.mean(torch.abs(x))
  
      if scale == 'l2':
          x_scale = torch.sqrt(torch.sum(x ** 2)) / n_features
  
      x /= x_scale
  
      return x
function_tokens: def global_contrast_normalization ( x : torch . tensor , scale = 'l2' ) : assert scale in ( 'l1' , 'l2' ) n_features = int ( np . prod ( x . shape ) ) mean = torch . mean ( x ) # mean over all features (pixels) per sample x -= mean if scale == 'l1' : x_scale = torch . mean ( torch . abs ( x ) ) if scale == 'l2' : x_scale = torch . sqrt ( torch . sum ( x ** 2 ) ) / n_features x /= x_scale return x