wiener_index(G, weight=None)
The Wiener index of a graph is the sum of the shortest-path distances between each pair of reachable nodes. For pairs of nodes in undirected graphs, only one orientation of the pair is counted.
If a pair of nodes is not reachable, the distance is assumed to be infinity. This means that for graphs that are not strongly-connected, this function returns inf
.
The Wiener index is not usually defined for directed graphs, however this function uses the natural generalization of the Wiener index to directed graphs.
The edge attribute to use as distance when computing shortest-path distances. This is passed directly to the networkx.shortest_path_length
function.
If the graph G
is not connected.
The Wiener index of the graph G
.
Returns the Wiener index of the given graph.
>>> n = 10 >>> G = nx.complete_graph(n) >>> nx.wiener_index(G) == n * (n - 1) / 2 True
See :>>> G = nx.empty_graph(2) >>> nx.wiener_index(G) inf
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