code: def _rescale(
      betweenness,
      n,
      normalized,
      directed=False,
      k=None,
      endpoints=False,
  ):
      if normalized:
          if endpoints:
              if n < 2:
                  scale = None  # no normalization
              else:
                  # Scale factor should include endpoint nodes
                  scale = 1 / (n * (n - 1))
          elif n <= 2:
              scale = None  # no normalization b=0 for all nodes
          else:
              scale = 1 / ((n - 1) * (n - 2))
      else:  # rescale by 2 for undirected graphs
          if not directed:
              scale = 0.5
          else:
              scale = None
      if scale is not None:
          if k is not None:
              scale = scale * n / k
          for v in betweenness:
              betweenness[v] *= scale
      return betweenness
  
file_path: networkx/networkx/algorithms/centrality/betweenness.py
imports: from collections import deque
  from heapq import heappop, heappush
  from itertools import count
  import networkx
  from networkx.algorithms.shortest_paths.weighted import _weight_function
  from networkx.utils import py_random_state
  from networkx.utils.decorators import not_implemented_for
label_desc: Use image node_id 8 for calling a global function with example usage: _rescale(betweenness, n, normalized, directed, k, endpoints) and returns: betweenness