geo*_*kos 7 python graph-theory networkx
我试图在不使用get_edge_attributes()函数的情况下从图形中获取具有特定属性的边.我需要一种更灵活的方式.我可以得到节点属性,但因为我在python边缘是新的似乎很难
G = nx.read_graphml("test.graphml")
for n in G:
print "%s\t%s" %(n, G.node[n].get(attr))
for (s,d) in G: # and here is my problem
print "%s->%s\t%s" %(s, d, G.edge[s][d].get(attr))
Run Code Online (Sandbox Code Playgroud)
您可以使用G.edges()或G.edges_iter()方法遍历所有图形边.
In [1]: import networkx as nx
In [2]: G = nx.Graph()
In [3]: G.add_edge(1,2,weight=7)
In [4]: G.add_edge(2,3,weight=10)
In [5]: for u,v,a in G.edges(data=True):
print u,v,a
...:
1 2 {'weight': 7}
2 3 {'weight': 10}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4338 次 |
最近记录: |