I believe the problem is the explanation of nodelist in the documentation.
Based on the documentation:
nodelist (list, optional) – The rows and columns are ordered by the nodes in nodelist. If nodelist is None then the ordering is produced by G.nodes().
But it does not mention the nodelist actually modifies the graph. It makes another graph using the nodes in nodelist.
Assume your Graph has 4 nodes [1,2,3,4] but you define the nodelist as [2,3,4]. When you read the documentation you think the function would calculate the distance matrix between nodes 2, 3, and 4 in the original graph. However, it seems it removes node 1 from the graph (technically changing the original graph) and then calculates the distance matrix between 2, 3, and 4. It can be problematic if node 1 is connecting nodes 2 and 3.
Sample Graph with 4 nodes
Dist_Mat=nx.algorithms.shortest_paths.dense.floyd_warshall_numpy(G,[1,2,3,4])
print(Dist_Mat)
[[0. 1. 1. 1.]
[1. 0. 2. 2.]
[1. 2. 0. 2.]
[1. 2. 2. 0.]]
Dist_Mat=nx.algorithms.shortest_paths.dense.floyd_warshall_numpy(G,[2,3,4])
print(Dist_Mat)
[[ 0. inf inf]
[inf 0. inf]
[inf inf 0.]]
please find the code below
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)