在 python 中从网络中提取边缘信息
Extracting edge information from network in python
我有以下网络:
net = nx.Graph()
node_list = ["Gur","Qing","Samantha","Jorge","Lakshmi","Jack","John","Jill"]
edge_list = [("Gur","Qing",{"source":"work"}),
("Gur","Jorge", {"source":"family"}),
("Samantha","Qing", {"source":"family"}),
("Jack","Qing", {"source":"work"}),
("Jorge","Lakshmi", {"source":"work"}),
("Jorge","Samantha",{"source":"family"}),
("Samantha","John", {"source":"family"}),
("Lakshmi","Jack", {"source":"family"}),
("Jack","Jill", {"source":"charity"}),
("Jill","John",{"source":"family"})]
net.add_nodes_from(nodes)
net.add_edges_from(edges)
在这个网络中,每个人都是一个节点,在这个节点中,所有节点都基于一种关系相互连接。在这种情况下,连接节点的关系是边缘。
我需要做的是提取边中包含的关系信息,以创建一个函数,给定人名和关系类型,根据指定的关系类型告诉其他人与哪些人有联系。
我正在使用 python 中的 networkx
包来执行此任务。由于我对网络完全陌生,这让我有点困惑,所以我会很感激对此的任何建议。
提前致谢
我要做的是创建一个新图,只包含与给定 "source" 匹配的边,例如对于 "family":
family = nx.Graph([(u,v,d) for u,v,d in net.edges(data=True) if d["source"]=="family"])
然后您可以使用
list(nx.bfs_tree(family, "Gur"))
获取完整的古尔家族
我有以下网络:
net = nx.Graph()
node_list = ["Gur","Qing","Samantha","Jorge","Lakshmi","Jack","John","Jill"]
edge_list = [("Gur","Qing",{"source":"work"}),
("Gur","Jorge", {"source":"family"}),
("Samantha","Qing", {"source":"family"}),
("Jack","Qing", {"source":"work"}),
("Jorge","Lakshmi", {"source":"work"}),
("Jorge","Samantha",{"source":"family"}),
("Samantha","John", {"source":"family"}),
("Lakshmi","Jack", {"source":"family"}),
("Jack","Jill", {"source":"charity"}),
("Jill","John",{"source":"family"})]
net.add_nodes_from(nodes)
net.add_edges_from(edges)
在这个网络中,每个人都是一个节点,在这个节点中,所有节点都基于一种关系相互连接。在这种情况下,连接节点的关系是边缘。
我需要做的是提取边中包含的关系信息,以创建一个函数,给定人名和关系类型,根据指定的关系类型告诉其他人与哪些人有联系。
我正在使用 python 中的 networkx
包来执行此任务。由于我对网络完全陌生,这让我有点困惑,所以我会很感激对此的任何建议。
提前致谢
我要做的是创建一个新图,只包含与给定 "source" 匹配的边,例如对于 "family":
family = nx.Graph([(u,v,d) for u,v,d in net.edges(data=True) if d["source"]=="family"])
然后您可以使用
list(nx.bfs_tree(family, "Gur"))
获取完整的古尔家族