Python networkx:floyd\u-WarmPy能正常工作吗?

Python networkx:floyd\u-WarmPy能正常工作吗?,python,networkx,floyd-warshall,Python,Networkx,Floyd Warshall,有人能证实我发现networkx 2.5的floyd_warshall_numpy方法的实现不正确吗 要复制的代码是: G = nx.balanced_tree(2, 3) print(G.nodes()) print(nx.shortest_path(G, 2, 13)) print(nx.floyd_warshall_numpy(G, [2, 8, 13])) 我的输出是 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] [2, 6, 1

有人能证实我发现networkx 2.5的floyd_warshall_numpy方法的实现不正确吗

要复制的代码是:

G = nx.balanced_tree(2, 3)
print(G.nodes())
print(nx.shortest_path(G, 2, 13))
print(nx.floyd_warshall_numpy(G, [2, 8, 13]))
我的输出是

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
[2, 6, 13]
[[ 0. inf inf]
 [inf  0. inf]
 [inf inf  0.]] 
我希望计算所有[2,8,13]节点对的非Inf距离,因为它们之间存在最短路径。在我看来,这个实现试图以某种方式在子图中找到路径

nx.floyd_warshall_numpy(G)
适用于所有节点。我发现这里的文档不直观。

我已经看过了源代码,现在的情况是,该算法只考虑与您给定的节点相关的路径

因此,由于在2和8之间没有只包含节点2、8和13的路径,因此它将返回
inf


我不确定应该如何修复它-更新文档还是更新方法更好。

我怀疑你的代码是说
打印(nx.floyd\u warshall\u numpy(G[2,6,13])
带有一组节点
[2,6,13]
而不是
[2,8,13]
。对吗

G = nx.balanced_tree(2, 3) 
print(G.nodes()) 
print(nx.shortest_path(G, 2, 13)) 
print(nx.floyd_warshall_numpy(G, [2, 6, 13]))                                                                         
产生

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
[2, 6, 13]
[[0. 1. 2.]
 [1. 0. 1.]
 [2. 1. 0.]]

我认为问题在于文档中对nodelist的解释。 根据文档:
节点列表(列表,可选)–行和列按节点列表中的节点排序。如果nodelist为None,则由G.nodes()生成排序。 但它没有提到节点列表实际上修改了图形。它使用nodelist中的节点生成另一个图

假设图形有4个节点[1,2,3,4],但将节点列表定义为[2,3,4]。阅读文档时,您认为该函数将计算原始图形中节点2、3和4之间的距离矩阵。但是,它似乎从图中删除了节点1(技术上更改了原始图),然后计算2、3和4之间的距离矩阵。如果节点1正在连接节点2和3,则可能会出现问题

请在下面查找代码

import networkx as nx
import matplotlib.pyplot as plt
import nxviz as nv
G=nx.Graph()
G.add_node(1)
G.nodes[1]['N']=10
G.add_nodes_from([(2,{'N':20}),3,4])
G.add_edge(1,2)
G.edges[1,2]['E']=120
G.add_edges_from([(1,3,{'E':130}),(1,4)])
G.nodes()
pos = {0: (0, 0),
       1: (1, 0),
       2: (0, 1),
       3: (1, 1),
       4: (0.5, 2.0)}
print(G.nodes(data=True))
print(G.edges(data=True))
nx.draw(G, pos, with_labels=True, font_weight='bold')
FIG=nv.CircosPlot(G,node_size=1)
FIG.draw();plt.show()

Dist_Mat=nx.algorithms.shortest_paths.dense.floyd_warshall_numpy(G,[1, 2,3,4])
print(Dist_Mat)
Dist_Mat=nx.algorithms.shortest_paths.dense.floyd_warshall_numpy(G,[2,3,4])
print(Dist_Mat)

我已经提交了一份错误报告:没有。我的目标是得到图G中节点之间的距离矩阵[2,8,13],其中G有节点[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]
import networkx as nx
import matplotlib.pyplot as plt
import nxviz as nv
G=nx.Graph()
G.add_node(1)
G.nodes[1]['N']=10
G.add_nodes_from([(2,{'N':20}),3,4])
G.add_edge(1,2)
G.edges[1,2]['E']=120
G.add_edges_from([(1,3,{'E':130}),(1,4)])
G.nodes()
pos = {0: (0, 0),
       1: (1, 0),
       2: (0, 1),
       3: (1, 1),
       4: (0.5, 2.0)}
print(G.nodes(data=True))
print(G.edges(data=True))
nx.draw(G, pos, with_labels=True, font_weight='bold')
FIG=nv.CircosPlot(G,node_size=1)
FIG.draw();plt.show()

Dist_Mat=nx.algorithms.shortest_paths.dense.floyd_warshall_numpy(G,[1, 2,3,4])
print(Dist_Mat)
Dist_Mat=nx.algorithms.shortest_paths.dense.floyd_warshall_numpy(G,[2,3,4])
print(Dist_Mat)