在网络x中找到符合特定标准的边缘 [英] finding edges in networkx that meet a certain criteria

查看:85
本文介绍了在网络x中找到符合特定标准的边缘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 networkx图,其节点上有属性,我想查找特定节点属性不同的所有边。有没有办法自动做到这一点,或者我必须迭代 edge_iter(data = True)并自己找到它们?



 <$> 

c $ c> import networkx as nx

G = nx.Graph()
G.add_node(1,color ='red')
G.add_node(2,color ='red')
G.add_node(3,color ='blue')
G.add_node(4,color ='blue')

G.add_edges_from([ (1,2),(1,3),(3,4)])

用于G.edges_iter()中的(u,v):
如果G.node [u ] ['color']!= G.node [v] ['color']:
print u,v


I have a networkx digraph with attributes on the nodes, and I want to find all edges where a particular node attribute is different. Is there a way to do this automatically, or do I have to iterate with edge_iter(data=True) and find them myself?

解决方案

There is no built-in function for this but it is pretty simple:

import networkx as nx

G = nx.Graph()
G.add_node(1,color='red')
G.add_node(2,color='red')
G.add_node(3,color='blue')
G.add_node(4,color='blue')

G.add_edges_from([(1,2),(1,3),(3,4)])

for (u,v) in G.edges_iter():
    if G.node[u]['color'] != G.node[v]['color']:
        print u,v

这篇关于在网络x中找到符合特定标准的边缘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆