python - iGraph: selecting vertices connected to -
suppose have following graph:
g = ig.graph([(0,1), (0,2), (2,3), (3,4), (4,2), (2,5), (5,0), (6,3), (5,6)], directed=false) g.vs["name"] = ["alice", "bob", "claire", "dennis", "esther", "frank", "george"]
and wish see bob connected to. bob connected 1 person alice. if try find edge :
g.es.select(_source=1) >>> <igraph.edgeseq @ 0x7f15ece78050>
i above response. how infer vertex index above. or if isn't possible, how find vertices connected bob?
this seems work. keyword arguments consist of property, e.g _source
, _target
, , operator e.g eq
(=). , seems need check both source , target of edges (even it's undirected graph), after filtering edges, can use list comprehension loop through edges , extract source or target:
connected_from_bob = [edge.target edge in g.es.select(_source_eq=1)] connected_to_bob = [edge.source edge in g.es.select(_target_eq=1)] connected_from_bob # [] connected_to_bob # [0]
then vertices connected bob union of 2 lists:
connected_with_bob = connected_from_bob + connected_to_bob
Comments
Post a Comment