1
我想執行獲得邊緣權重,但我遇到了問題。通過頂點獲得邊緣權重編號
首先,我想這一點:
from igraph import *
g = Nexus.get("karate")
weight = g.es[g.get_eid(vertex, neighbor)]['weight']
但是,如果邊緣不存在的igraph回報埃羅。我想,例如,只返回-1
第二,從IGRAPH有更高效的計算操作/函數嗎?
我想執行獲得邊緣權重,但我遇到了問題。通過頂點獲得邊緣權重編號
首先,我想這一點:
from igraph import *
g = Nexus.get("karate")
weight = g.es[g.get_eid(vertex, neighbor)]['weight']
但是,如果邊緣不存在的igraph回報埃羅。我想,例如,只返回-1
第二,從IGRAPH有更高效的計算操作/函數嗎?
:
from igraph import *
g = Nexus.get("karate")
weight = g.es.select(_source=0, _target=1)['weight']
print weight
get_eid(v1, v2, directed=True, error=True)
@param error: if C{True}, an exception will be raised when the
given edge does not exist. If C{False}, -1 will be returned in
that case.
所以,你的情況,這意味着當沒有邊時,它返回空集。
似乎有是,在get_eid
方法關鍵字:我喜歡這個
weight = g.es[g.get_eid(vertex, neighbor, error=False)]['weight']