使用numpy及scipy函式庫,計算最短路徑。
mport numpy as np
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
arr = np.array([
[0, 11, 2],
[2, 3, 3],
[3, 4, 5]
])
newarr = csr_matrix(arr)
print(dijkstra(newarr, return_predecessors=True, indices=0))