python - NetworkX: How to find the source and target nodes of a directed edge -


dito above.. couldn't find in networkx docs...

in python igraph, can use:

import igraph ig g = ig.graph(directed=true) g.add_vertices(2) g.add_edge(0,1) eid = g.get_eid(0,1) edge = g.es[eid] nodes = (edge.source, edge.target) print nodes 

the ordering of tuples significant. first element source , second target.

in [1]: import networkx nx  in [2]: g = nx.digraph()  in [3]: g.add_edge(1,2) # 1->2  in [4]: g.add_edge(2,3) # 2->3  in [5]: list(g.edges()) out[5]: [(1, 2), (2, 3)] # 1->2 , 2->3  in [6]: g.add_edge(42,17) # 42->17  in [7]: list(g.edges()) out[7]: [(1, 2), (2, 3), (42, 17)]  in [8]: e in g.edges():    ...:     source,target = e    ...:     print source    ...:      1 2 42 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -