Pergunta

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?

Foi útil?

Solução 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.

Outras dicas

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']
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top