code: def trophic_differences(G, weight="weight"):
      r"""Compute the trophic differences of the edges of a directed graph.
  
      The trophic difference $x_ij$ for each edge is defined in Johnson et al.
      [1]_ as:
  
      .. math::
          x_ij = s_j - s_i
  
      Where $s_i$ is the trophic level of node $i$.
  
      Parameters
      ----------
      G : DiGraph
          A directed networkx graph
  
      Returns
      -------
      diffs : dict
          Dictionary of edges with trophic differences as the value.
  
      References
      ----------
      .. [1] Samuel Johnson, Virginia Dominguez-Garcia, Luca Donetti, Miguel A.
          Munoz (2014) PNAS "Trophic coherence determines food-web stability"
      """
      levels = trophic_levels(G, weight=weight)
      diffs = {}
      for u, v in G.edges:
          diffs[(u, v)] = levels[v] - levels[u]
      return diffs
  
imports: import networkx
  from networkx.utils import not_implemented_for
label_desc: Use image node_id 2 for calling a global function with example usage: trophic_differences(G, weight) and returns: diffs