def floyd_warshall(adj_matrix):
# Number of vertices in the graph
n = adj_matrix.shape[0]
# Convert adjacency matrix to float type and initialize the distance matrix
dist_matrix = np.array(adj_matrix, dtype=float)
# Set distance from every vertex to itself as 0
for i in range(n):
dist_matrix[i][i] = 0
# Set distance for non-adjacent vertices as infinity
for i in range(n):
for j in range(n):
if i != j and dist_matrix[i][j] == 0:
dist_matrix[i][j] = float('inf')
# Check and update shortest path using Floyd-Warshall algorithm
for k in range(n):
for i in range(n):
for j in range(n):
if dist_matrix[i][j] > dist_matrix[i][k] + dist_matrix[k][j]:
dist_matrix[i][j] = dist_matrix[i][k] + dist_matrix[k][j]
return dist_matrix