[英]Select individual edges by source-target-tuple in python 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.