Skip to main content
`Ctrl`+`K`

# MultiGraph.to_directed

MultiGraph.to_directed(as_view=False)

  Returns a directed representation of the graph.

  Returns:
    G MultiDiGraph

      A directed graph with the same name, same nodes, and with each edge (u, v, k, data) replaced by two directed edges (u, v, k, data) and (v, u, k, data).

  Notes

  This returns a “deepcopy” of the edge, node, and graph attributes which attempts to completely copy all of the data and references.

  This is in contrast to the similar D=MultiDiGraph(G) which returns a shallow copy of the data.

  See the Python copy module for more information on shallow and deep copies, https://docs.python.org/3/library/copy.html.

  Warning: If you have subclassed MultiGraph to use dict-like objects in the data structure, those changes do not transfer to the MultiDiGraph created by this method.

  Examples

      >>> G = nx.MultiGraph()
      >>> G.add_edge(0, 1)
      0
      >>> G.add_edge(0, 1)
      1
      >>> H = G.to_directed()
      >>> list(H.edges)
      [(0, 1, 0), (0, 1, 1), (1, 0, 0), (1, 0, 1)]

  If already directed, return a (deep) copy

      >>> G = nx.MultiDiGraph()
      >>> G.add_edge(0, 1)
      0
      >>> H = G.to_directed()
      >>> list(H.edges)
      [(0, 1, 0)]