networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersRaisesReturnsBackRef
floyd_warshall_numpy(G, nodelist=None, weight='weight')

This algorithm for finding shortest paths takes advantage of matrix representations of a graph and works well for dense graphs where all-pairs shortest path lengths are desired. The results are returned as a NumPy array, distance[i, j], where i and j are the indexes of two nodes in nodelist. The entry distance[i, j] is the distance along a shortest path from i to j. If no path exists the distance is Inf.

Notes

Floyd's algorithm is appropriate for finding shortest paths in dense graphs or graphs with negative weights when Dijkstra's algorithm fails. This algorithm can still fail if there are negative cycles. It has running time $O(n^3)$ with running space of $O(n^2)$.

Parameters

G : NetworkX graph
nodelist : list, optional (default=G.nodes)

The rows and columns are ordered by the nodes in nodelist. If nodelist is None then the ordering is produced by G.nodes. Nodelist should include all nodes in G.

weight: string, optional (default='weight') :

Edge data key corresponding to the edge weight.

Raises

NetworkXError

If nodelist is not a list of the nodes in G.

Returns

distance : 2D numpy.ndarray

A numpy array of shortest path distances between nodes. If there is no path between two nodes the value is Inf.

Find all-pairs shortest path lengths using Floyd's algorithm.

Examples

See :

Back References

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

networkx.algorithms.shortest_paths.dense.floyd_warshall_predecessor_and_distance networkx.algorithms.shortest_paths.dense.floyd_warshall networkx.algorithms.shortest_paths.weighted.johnson

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/algorithms/shortest_paths/dense.py#13
type: <class 'function'>
Commit: