2024-04-19 22:03:13 发布
网友
在networkx中,我试图从txt文件导入图形。在
图形格式如下(例如:):
a b a c b d c e
Thtat的意思是:a--b a--c b--d c--e
a--b a--c b--d c--e
我想这是一个边缘列表,所以我尝试使用适当的命令:
但它不起作用,有什么想法吗?在
你在找这样的东西吗?在
import networkx as nx with open('a.txt') as f: lines = f.readlines() myList = [line.strip().split() for line in lines] # [['a', 'b'], ['a', 'c'], ['b', 'd'], ['c', 'e']] g = nx.Graph() g.add_edges_from(myList) print g.nodes() # ['a', 'c', 'b', 'e', 'd'] print g.edges() # [('a', 'c'), ('a', 'b'), ('c', 'e'), ('b', 'd')]
你在找这样的东西吗?在
相关问题 更多 >
编程相关推荐