Reputation: 1315
I want to perform get edges weight, but I am having problems.
First, I tried this:
from igraph import *
g = Nexus.get("karate")
weight = g.es[g.get_eid(vertex, neighbor)]['weight']
But, if edge not exist igraph return erro. I want, for instance, that only returns -1
Second, there is operation/function computationally more efficient than this from IGRAPH?
Upvotes: 2
Views: 1688
Reputation: 1315
I like this:
from igraph import *
g = Nexus.get("karate")
weight = g.es.select(_source=0, _target=1)['weight']
print weight
This returns empty set when there isn't edge.
Upvotes: 0
Reputation: 3923
It seems there is a keyword for that in the get_eid
method:
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.
So, in your case that means:
weight = g.es[g.get_eid(vertex, neighbor, error=False)]['weight']
Upvotes: 2