code: def scale(
      values, target_min, target_max, source_min=None, source_max=None
  ):
      """Scale the value of a numpy array "values"
      from source_min, source_max into a range [target_min, target_max]
  
      Parameters
      ----------
      values : Numpy array, required
          Values to be scaled.
  
      target_min : scalar, required
          Target minimum value.
  
      target_max : scalar, required
          Target maximum value.
  
      source_min : scalar, required, default: None
          Source minimum value if desired. If None, it will be the minimum of values.
  
      source_max : scalar, required, default: None
          Source minimum value if desired. If None, it will be the maximum of values.
  
      Returns
      -------
      res: Numpy array
          Output values mapped into range [target_min, target_max]
      """
      if source_min is None:
          source_min = np.min(values)
      if source_max is None:
          source_max = np.max(values)
      if source_min == source_max:  # improve this scenario
          source_min = 0.0
  
      values = (values - source_min) / (source_max - source_min)
      values = values * (target_max - target_min) + target_min
      return values
  
file_path: cornac/cornac/utils/common.py
imports: import numbers
  import numpy
  import scipy.sparse
  from .fast_sparse_funcs import inplace_csr_row_normalize_l1, inplace_csr_row_normalize_l2
label_desc: Use image node_id 2 for calling a global function with example usage: scale(values, target_min, target_max, source_min, source_max) and returns: values