code: def _get_diagonal_indices(flattened_indices):
      axes_contraction = defaultdict(list)
      for i, ind in enumerate(flattened_indices):
          if isinstance(ind, (int, Integer)):
              # If the indices is a number, there can be no diagonal operation:
              continue
          axes_contraction[ind].append(i)
      axes_contraction = {
          k: v for k, v in axes_contraction.items() if len(v) > 1
      }
      # Put the diagonalized indices at the end:
      ret_indices = [
          i for i in flattened_indices if i not in axes_contraction
      ]
      diag_indices = list(axes_contraction)
      diag_indices.sort(key=lambda x: flattened_indices.index(x))
      diagonal_indices = [
          tuple(axes_contraction[i]) for i in diag_indices
      ]
      ret_indices += diag_indices
      ret_indices = tuple(ret_indices)
      return diagonal_indices, ret_indices
  
file_path: sympy/sympy/tensor/array/expressions/utils.py
imports: import bisect
  from collections import defaultdict
  from sympy.combinatorics import Permutation
  from sympy.core.containers import Tuple
  from sympy.core.numbers import Integer
label_desc: Use image node_id 4 for calling a global function with example usage: _get_diagonal_indices(flattened_indices) and returns: diagonal_indices,  ret_indices