def floyd_warshall_numpy(G, nodelist=None, weight='weight'):
    """Find all-pairs shortest path lengths using Floyd's algorithm.

    Parameters
    ----------
    G : NetworkX graph

    nodelist : list, optional
       The rows and columns are ordered by the nodes in nodelist.
       If nodelist is None then the ordering is produced by G.nodes().

    weight: string, optional (default= 'weight')
       Edge data key corresponding to the edge weight.

    Returns
    -------
    distance : NumPy matrix
        A matrix of shortest path distances between nodes.
        If there is no path between to nodes the corresponding matrix entry
        will be 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).
    """
    try:
        import numpy as np
    except __HOLE__:
        raise ImportError(\
          "to_numpy_matrix() requires numpy: http://scipy.org/ ")
    A = nx.to_numpy_matrix(G, nodelist=nodelist, multigraph_weight=min,
                           weight=weight)
    n,m = A.shape
    I = np.identity(n)
    A[A==0] = np.inf # set zero entries to inf
    A[I==1] = 0 # except diagonal which should be zero
    for i in range(n):
        A = np.minimum(A, A[i,:] + A[:,i])
    return A
dataset/ETHPy150Open gkno/gkno_launcher/src/networkx/algorithms/shortest_paths/dense.py/floyd_warshall_numpy