NetworkX

Previous topic

networkx.DiGraph.to_undirected

Next topic

networkx.DiGraph.subgraph

networkx.DiGraph.to_directed

DiGraph.to_directed()

Return a directed copy of the graph.

Returns:

G : DiGraph

A deepcopy of the graph.

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=DiGraph(G) which returns a shallow copy of the data.

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

Examples

>>> G = nx.Graph()   # or MultiGraph, etc
>>> G.add_path([0,1])
>>> H = G.to_directed()
>>> H.edges()
[(0, 1), (1, 0)]

If already directed, return a (deep) copy

>>> G = nx.DiGraph()   # or MultiDiGraph, etc
>>> G.add_path([0,1])
>>> H = G.to_directed()
>>> H.edges()
[(0, 1)]