簡體   English   中英

在igraph中基於源/目標選擇邊

[英]selecting edges based on source/target in igraph

有沒有一種簡單的方法可以根據igraph中的源和目標選擇/刪除邊緣?

我使用的基本上是

g.es["source"] = [e.source for e in g.es]
g.es["target"] = [e.target for e in g.es]    
g.es["tuple"]  = [e.tuple  for e in g.es]        

g.es.select(target=root)

但我覺得應該有一種方法可以做到這一點,而無需兩次存儲源/目標信息。

只需使用_source=whatever_target=whatever作為關鍵字參數進行select ,例如:

g.es.select(_source=root)

或者,您可以使用圖表的incident方法,如果更適合您的目的,它會為您提供邊緣ID列表而不是過濾后的EdgeSeq

g.incident(root, mode="out")

順便說一句,對於'元組',你想使用_between

g.es.find(_between=((source_id,), (target_id,)))

它看起來很奇怪 - 如果你使用select而不是find ,並傳入帶有多個索引的元組,你實際上會得到一個邊列表而不是一個邊。 但是對於單個邊緣,還必須通過一個元組來開始和結束。

由於某種原因(比使用_source_target的組合快3個數量級!),這種方式更快,但提供完全相同的信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM