[英]read the edge list from a csv file and create a graph with networkx
[英]Failing to read from edge list in networkx
計算最短路徑似乎不適合我:
import networkx as nx
G = nx.read_edgelist(filename, delimiter=",", create_using=nx.DiGraph(), nodetype=int)
print G
print nx.shortest_path(G, 1, 5)
我正在閱讀的文件是:
1,2
2,3
3,4
4,5
沒有輸出。
你的代碼適合我。
import networkx as nx
import matplotlib.pyplot as plt
filename = 'test.txt'
G = nx.read_edgelist(filename, delimiter=",", create_using=nx.DiGraph(), nodetype=int)
nx.draw_networkx(G, with_labels=True)
plt.axis('off')
plt.show()
print(type(G), G)
# (<class 'networkx.classes.digraph.DiGraph'>, <networkx.classes.digraph.DiGraph object at 0x10e29c150>)
print(nx.shortest_path(G, 1, 5))
#[1, 2, 3, 4, 5]
哪個產生,
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.