Warning

The documentation for retworkx has migrated to:

https://qiskit.org/documentation/retworkx

These docs will no longer be updated.

# retworkx.digraph_floyd_warshall_numpy¶

- digraph_floyd_warshall_numpy()¶
Find all-pairs shortest path lengths using Floyd’s algorithm

Floyd’s algorithm is used for finding shortest paths in dense graphs or graphs with negative weights (where Dijkstra’s algorithm fails).

- Parameters
**graph**(*PyDiGraph*) – The directed graph to run Floyd’s algorithm on**weight_fn**–A callable object (function, lambda, etc) which will be passed the edge object and expected to return a

`float`

. This tells retworkx/rust how to extract a numerical weight as a`float`

for edge object. Some simple examples are:graph_floyd_warshall_numpy(graph, weight_fn: lambda x: 1)

to return a weight of 1 for all edges. Also:

graph_floyd_warshall_numpy(graph, weight_fn: lambda x: float(x))

to cast the edge object as a float as the weight.

**as_undirected**– If set to true each directed edge will be treated as bidirectional/undirected.

- Returns
A matrix of shortest path distances between nodes. If there is no path between two nodes then the corresponding matrix entry will be

`np.inf`

.- Return type
numpy.ndarray