code: def floyd_warshall_slow(graph, directed=False):
      N = graph.shape[0]
  
      # set nonzero entries to infinity
      graph[np.where(graph == 0)] = np.inf
  
      # set diagonal to zero
      graph.flat[:: N + 1] = 0
  
      if not directed:
          graph = np.minimum(graph, graph.T)
  
      for k in range(N):
          for i in range(N):
              for j in range(N):
                  graph[i, j] = min(
                      graph[i, j], graph[i, k] + graph[k, j]
                  )
  
      graph[np.where(np.isinf(graph))] = 0
  
      return graph
  
imports: from collections import defaultdict
  import numpy
  from numpy.testing import assert_array_almost_equal
  from sklearn.utils.graph import single_source_shortest_path_length
label_desc: Use image node_id 1 for calling a global function with example usage: floyd_warshall_slow(graph, directed) and returns: graph