Skip to content
Advertisement

igraph: get dict with nodes and corresponding attribute

I have a large igraph network and want to get some attributes of the vertices in the network. I have created a directed graph and want to run some algorithms:

G = ig.Graph.from_networkx(g)
obj = ig.Graph.authority_score(G)
print(obj)

When I print the list it just gives me list of the authority scores of the vertices. However I would like to know which node exactly has each value. Is there anyway to generate a dict that shows the correlation? In NetworkX one can do something like this:

obj = {node: g.degree(node) for node in g}

But igraph says the Graph is not iterable. Anyone have any ideas?

Advertisement

Answer

You can recover the original networkx node identifiers using

nx_ids = G.vs.get_attribute_values('_nx_name')

You can then create your dictionary of node, authority pairs with

authority_dict = dict(zip(nx_ids, obj))
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement