python 的 igraph 包是否包含计算图形距离矩阵的方法?

Does the igraph package for python contain a method to compute the distance matrix of a graph?

igraph 包的 R 版本包含 distances 函数,根据文档,returns 传递给它的图的距离矩阵。

但是,我在 python 版本的软件包中找不到此功能或类似功能。我能找到的唯一提供的函数是 Point.distance,根据我对文档的理解,它只计算二维平面中两点的距离,而不是网络图。

在这个包的 python 版本中是否有 returns 图形距离矩阵的函数?

基本上,我正在寻找的是以下内容:

# create the graph
graph = Graph(n=5, edges=[(0,1), (1,4), (2,3), (2,4), (2,5) , (3,5), (4,0)], directed=False)

# pseudo code to calculate distance
dist_matrix = distances(graph)

非常感谢任何帮助。

其中一种方法是使用 g.get_all_shortest_paths(m)

import igraph as ig
g = ig.Graph(n=5, edges=[(0,1), (1,4), (2,3), (2,4), (2,5) , (3,5), (4,0)], directed=False)
>>> [[len(n) for n in g.get_all_shortest_paths(m)] for m in g.vs]
[[1, 2, 3, 4, 2, 4], [2, 1, 3, 4, 2, 4], [3, 3, 1, 2, 2, 2], [4, 4, 2, 1, 3, 2], [2, 2, 2, 3, 1, 3], [4, 4, 2, 2, 3, 1]]

另一种选择更简单快捷:

>>> g.shortest_paths()
[[0, 1, 2, 3, 1, 3], [1, 0, 2, 3, 1, 3], [2, 2, 0, 1, 1, 1], [3, 3, 1, 0, 2, 1], [1, 1, 1, 2, 0, 2], [3, 3, 1, 1, 2, 0]]