Skip to content
Advertisement

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

dito above.. I couldn’t find anything in the NetworkX docs…

In Python Igraph, i can just use:

JavaScript

Advertisement

Answer

Event though I came too late I want to contribute with my proposal, since I was looking for the same answer:

I am also looking for a command in the networkx package to find the “sources” and the “targets” of a Directed graph. But “sources” and “targets” of a Directed graph within the frame of Graph Theory are not simply the sources and targets of each edge as replied in this thread, but the equivalent of leaves for an undirected Graph. That is, source and target nodes whose degree is 1 (in different direction, of course).

I’d propose the following code:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement