是否有任何函数可以返回节点的外边缘?

发布于 2024-08-19 23:15:04 字数 101 浏览 2 评论 0原文

我正在使用 python 和 networkx 包。我需要找到连接到给定节点的外边缘的节点。 我知道有一个函数 networkx.DiGraph.out_edges 但它返回整个图的边缘。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初见你 2024-08-26 23:15:04

我不是networkx专家,但是你尝试过networkx.DiGraph.out_edges,指定源节点?

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

返回边列表。

边以元组的形式返回,其中可选数据的顺序为(节点、
邻居,数据)。

如果您只想要单个节点的外边缘,请将该节点传递到 nbunch 内部:

graph.out_edges([my_node])

I'm not a networkx expert, but have you tried networkx.DiGraph.out_edges, specifying the source node?

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

Return a list of edges.

Edges are returned as tuples with optional data in the order (node,
neighbor, data).

If you just want the out edges for a single node, pass that node in inside the nbunch:

graph.out_edges([my_node])
戏剧牡丹亭 2024-08-26 23:15:04

最简单的方法是使用 successors() 方法:

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]

The simplest 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]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文