MultiGraph.to_undirected#

MultiGraph.to_undirected(as_view=False)[source]#

Returns an undirected copy of the graph.

Returns:
GGraph/MultiGraph

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 G = nx.MultiGraph(D) 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 MultiGraph created by this method.

Examples

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