Is there any function that returns the outer faces of a node?

I am using python with networkx package. I need to find the nodes connected to the edges of the given node. I know that there is a networkx.DiGraph.out_edges function, but it returns edges for the entire graph.

+3
source share
2 answers

I am not an expert on the network, but have you tried networkx.DiGraph.out_edges by specifying the source of the node?

DiGraph.out_edges(nbunch=None, data=False)

Returns a list of edges.

The edges are returned in the form of tuples with additional data in order (node, neighbor, data).

If you just want to cut the edges for one node, skip the node inside nbunch:

graph.out_edges([my_node])
+4
source

The easiest way is to use the successors () method:

In [1]: import networkx as nx

In [2]: G=nx.DiGraph([(0,1),(1,2)])

In [3]: G.edges()
Out[3]: [(0, 1), (1, 2)]

In [4]: G.successors(1)
Out[4]: [2]
+4
source

Source: https://habr.com/ru/post/1731188/


All Articles