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, nonedge=np.inf)
 (n, m) = A.shape
 I = np.identity(n)
 A[(I == 1)] = 0
 for i in range(n):
  A = np.minimum(A, (A[i, :] + A[:, i]))
 return A

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 , nonedge = np . inf ) ( n , m ) = A . shape I = np . identity ( n ) A [ ( I == 1 ) ] = 0 for i in range ( n ) : A = np . minimum ( A , ( A [ i , : ] + A [ : , i ] ) ) return A
find all-pairs shortest path lengths using floyds algorithm .