NetworkX

Previous topic

networkx.DiGraph.copy

Next topic

networkx.DiGraph.subgraph

networkx.DiGraph.to_undirected

DiGraph.to_undirected()

Return an undirected representation of the digraph.

Returns:

G : Graph

An undirected graph with the same name and nodes and with edge (u,v,data) if either (u,v,data) or (v,u,data) is in the digraph. If both edges exist in digraph and their edge data is different, only one edge is created with an arbitrary choice of which edge data to use. You must check and correct for this manually if desired.

Notes

If edges in both directions (u,v) and (v,u) exist in the graph, attributes for the new undirected edge will be a combination of the attributes of the directed edges. The edge data is updated in the (arbitrary) order that the edges are encountered. For more customized control of the edge attributes use add_edge().

This is similar to Graph(self) which returns a shallow copy. self.to_undirected() returns a deepcopy of edge, node and graph attributes.