Warning
This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.
to_undirected¶
-
MultiDiGraph.
to_undirected
(reciprocal=False)[source]¶ Return an undirected representation of the digraph.
Parameters: reciprocal : bool (optional)
If True only keep edges that appear in both directions in the original digraph.
Returns: G : MultiGraph
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
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.