Project 10: Shortest Path Finder
Scientific Computing
Builds on these lessons
Current Task
Objective
scipy.sparse.csgraph.shortest_path() computes the shortest distance between every pair of nodes in a weighted graph, given as an adjacency matrix.
Task: compute all-pairs shortest paths over a small distance matrix and print the result.
index.py
from scipy.sparse.csgraph import shortest_path
import numpy as np
distances = np.array([
[0, 4, 0],
[4, 0, 2],
[0, 2, 0]
])
result = shortest_path(distances)
print(result)
* Hint: Correct characters turn green, incorrect ones turn red.
Live Preview
🖼️
Verify your code to see the preview