2014-04-09 2 views
1

가장자리 모으기를 수행하고 싶지만 문제가 있습니다. 가장자리 igraph 반환 에로 존재하지 않을 경우,정점 ID로 가장자리 무게 얻기

from igraph import * 
g = Nexus.get("karate") 
weight = g.es[g.get_eid(vertex, neighbor)]['weight'] 

그러나 :

첫째,이 시도. 예를 들어, 그게 단지 -1을 반환하고 싶습니다.

둘째로 IGRAPH에서 연산보다 연산이 더 효율적입니까?

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. 

따라서, 귀하의 경우 의미 :

weight = g.es[g.get_eid(vertex, neighbor, error=False)]['weight'] 

답변

1

나는이 같은 :

from igraph import * 
g = Nexus.get("karate") 
weight = g.es.select(_source=0, _target=1)['weight'] 
print weight 

0

get_eid 방법이라는 키워드가 보인다 가장자리가없는 경우 빈 세트를 반환합니다.

관련 문제