Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个格式为:
1,2
2,3
1,3
等等(每对代表两个节点之间的一条边,例如,'1,2' 是节点 1 和节点 2 之间的一条边)
我需要将其读入networkx。目前我正在尝试将其作为列表读取,其中每一对都是列表中的一个元素,但这不起作用。
您可以使用 networkx.read_edgelist(file, demeter=',')。
例如
import StringIO import networkx as nx data = StringIO.StringIO("""1,2 2,3 1,3 """) G = nx.read_edgelist(data, delimiter=',', nodetype=str) for e in G.edges(): print e # ('1', '3') # ('1', '2') # ('3', '2')