MultiDiGraph.to_undirected¶
- MultiDiGraph.to_undirected(reciprocal=False, as_view=False)[source]¶
Returns an undirected representation of the digraph.
- Parameters
- reciprocalbool (optional)
If True only keep edges that appear in both directions in the original digraph.
- as_viewbool (optional, default=False)
If True return an undirected view of the original directed graph.
- Returns
- GMultiGraph
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.
See also
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 MultiDiGraph to use dict-like objects in the data structure, those changes do not transfer to the MultiGraph created by this method.
Examples
>>> G = nx.path_graph(2) # or MultiGraph, etc >>> H = G.to_directed() >>> list(H.edges) [(0, 1), (1, 0)] >>> G2 = H.to_undirected() >>> list(G2.edges) [(0, 1)]