code: def permute_graph(graph, label, permutation):
      """Permutes the graph and labels based on permutation.
  
      Args:
        graph: np.ndarray adjacency matrix.
        label: list of labels of same length as graph dimensions.
        permutation: a permutation list of ints of same length as graph dimensions.
  
      Returns:
        np.ndarray where vertex permutation[v] is vertex v from the original graph
      """
      # vertex permutation[v] in new graph is vertex v in the old graph
      forward_perm = zip(permutation, list(range(len(permutation))))
      inverse_perm = [x[1] for x in sorted(forward_perm)]
      edge_fn = (
          lambda x, y: graph[inverse_perm[x], inverse_perm[y]] == 1
      )
      new_matrix = np.fromfunction(
          np.vectorize(edge_fn), (len(label), len(label)), dtype=np.int8
      )
      new_label = [label[inverse_perm[i]] for i in range(len(label))]
      return new_matrix, new_label
  
file_path: singa/examples/model_selection/TRAILS-Database-Native-Model-Selection/internal/ml/model_selection/src/third_pkg/sp101_lib/graph_util.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import hashlib
  import itertools
  import numpy
label_desc: Use image node_id 5 for calling a global function with example usage: permute_graph(graph, label, permutation) and returns: new_matrix,  new_label