def floyd_warshall_numpy(G, nodelist=None, weight='weight'):
    try:
        import numpy as np
    except ImportError:
        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
Find all-pairs shortest path lengths using Floyd's algorithm.
dataset/ETHPy150Open gkno/gkno_launcher/src/networkx/algorithms/shortest_paths/dense.py/floyd_warshall_numpy