node_attribute_xy#

node_attribute_xy(G, attribute, nodes=None)[源代码]#

返回G中所有边的节点属性对的迭代器。

参数
G: NetworkX graph
attribute: key

节点属性键。

nodes: list or iterable (optional)

仅使用与指定节点关联的边。默认为所有节点。

返回
(x,y):2元组

生成(属性、属性)值的二元组。

笔记

对于无向图,每条边被产生两次,每个边表示(u,v)和(v,u)一次,除了只出现一次的自循环边。

实例

>>> G = nx.DiGraph()
>>> G.add_node(1, color="red")
>>> G.add_node(2, color="blue")
>>> G.add_edge(1, 2)
>>> list(nx.node_attribute_xy(G, "color"))
[('red', 'blue')]