networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
to_undirected(self, reciprocal=False, as_view=False)

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 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=DiGraph(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 DiGraph to use dict-like objects in the data structure, those changes do not transfer to the Graph created by this method.

Parameters

reciprocal : bool (optional)

If True only keep edges that appear in both directions in the original digraph.

as_view : bool (optional, default=False)

If True return an undirected view of the original directed graph.

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.

Returns an undirected representation of the digraph.

See Also

Graph
add_edge
add_edges_from
copy

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)]
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.classes.graph.Graph.to_undirected networkx.generators.directed.gn_graph networkx.classes.multidigraph.MultiDiGraph.to_undirected networkx.generators.directed.gnr_graph networkx.classes.digraph.DiGraph.to_undirected

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/classes/digraph.py#1132
type: <class 'function'>
Commit: