[英]iGraph: selecting vertices connected to
假設我有以下圖形:
g = ig.Graph([(0,1), (0,2), (2,3), (3,4), (4,2), (2,5), (5,0), (6,3), (5,6)], directed=False)
g.vs["name"] = ["Alice", "Bob", "Claire", "Dennis", "Esther", "Frank", "George"]
我想看看鮑勃與誰有聯系。 鮑勃僅與一個人愛麗絲相連。 但是,如果嘗試找到邊緣:
g.es.select(_source=1)
>>> <igraph.EdgeSeq at 0x7f15ece78050>
我只是得到上述答復。 我如何從上面推斷出頂點索引是什么。 或者,如果那不可能,我如何找到連接到Bob的頂點?
這似乎有效。 關鍵字參數由屬性(例如_source
和_target
)和運算符(例如eq
(=))組成。 而且似乎還需要檢查邊緣的源和目標(即使它是無向圖),在過濾邊緣之后,可以使用列表推導遍歷邊緣並提取源或目標 :
connected_from_bob = [edge.target for edge in g.es.select(_source_eq=1)]
connected_to_bob = [edge.source for edge in g.es.select(_target_eq=1)]
connected_from_bob
# []
connected_to_bob
# [0]
然后與Bob相連的頂點是兩個列表的並集:
connected_with_bob = connected_from_bob + connected_to_bob
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.