code: def graph_to_laplacian(G, normalized=True):
      
      try:
          import networkx as nx
          if isinstance(G, nx.Graph):
              if normalized:
                  return nx.normalized_laplacian_matrix(G)
              else:
                  return nx.laplacian_matrix(G)
      except ImportError:
          pass
      try:
          import graph_tool.all as gt
          if isinstance(G, gt.Graph):
              if normalized:
                  return gt.laplacian_type(G, normalized=True)
              else:
                  return gt.laplacian(G)
      except ImportError:
          pass
      try:
          import igraph as ig
          if isinstance(G, ig.Graph):
              if normalized:
                  return np.array(G.laplacian(normalized=True))
              else:
                  return np.array(G.laplacian())
      except ImportError:
          pass
docs: Converts a graph from popular Python packages to Laplacian representation.
  
      Currently support NetworkX, graph_tool and igraph.
      
      Parameters
      ----------
      G : obj
          Input graph
      normalized : bool
          Whether to use normalized Laplacian.
          Normalized and unnormalized Laplacians capture different properties of graphs, e.g. normalized Laplacian spectrum can determine whether a graph is bipartite, but not the number of its edges. We recommend using normalized Laplacian.
  
      Returns
      -------
      scipy.sparse
          Laplacian matrix of the input graph
  
      Examples
      --------
      >>> graph_to_laplacian(nx.complete_graph(3), 'unnormalized').todense()
      [[ 2, -1, -1], [-1,  2, -1], [-1, -1,  2]]
  
      >>> graph_to_laplacian('test')
      None