igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] how to select eid on the basis of an edge attribute


From: Tamas Nepusz
Subject: Re: [igraph] how to select eid on the basis of an edge attribute
Date: Sun, 25 Jan 2009 16:38:53 +0000

I guess this can work:
Yup, this can work, but this one might be faster:

nei_edges = g.adjacent(v1, type="in")
friends = [edge.tuple[0] for edge in g.es.select(nei_edges, color="blue")]

(note that in a directed graph, this applies only to incoming edges. In an undirected graph, type="..." is ignored and you get all the adjacent edges).

The reason why it is faster is that Python handles list comprehensions (expressions like [foo for foo in bar]) faster than "real" for loops. (Also, g.es.select(nei_edges, color="blue") selects all the blue edges among nei_edges in the C layer at once).

--
T.



friend=[]
nei_edges = g.adjacent(v1, type="in")
for nei_edge in nei_edges:
  if g.es[nei_edge]["color"] == "blue":
        friend.append(g.es[nei_edge].tuple[0])

cheers,
Simone

2009/1/22 Tamas Nepusz <address@hidden>:
Hi Simone,

Could this be the a good strategy?

1) find all the neighbors of v1:

2) for each neighbor in the list:

3) check if they are blue-linked with v1 (using get_eids()):

Yup, but since you will be checking the _edges_ adjacent to v1, you should
find the adjacent edges in step 1 instead of the neighbours. So:

nei_edges = g.adjacent(v1)
for nei_edge in nei_edges:
if g.es[nei_edge]["color"] == "blue":
  # do this
else:
  # do that

--
T.


_______________________________________________
igraph-help mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/igraph-help



_______________________________________________
igraph-help mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/igraph-help





reply via email to

[Prev in Thread] Current Thread [Next in Thread]