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?

有帮助吗?

解决方案 2

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.

其他提示

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']
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top