[graph-tool] Building graph from adjacency matrix

Pietro Battiston ml at pietrobattiston.it
Thu Mar 20 18:25:27 CET 2014


Il giorno gio, 20/03/2014 alle 12.52 +0100, Tiago de Paula Peixoto ha
scritto:
> [...]I have now just added a Graph.add_edge_list() to the
> git version, which takes a list of edges to be added, which can be a
> numpy array. If you have a full adjacency matrix instead of an edge
> list, you can do simply:
> 
>     g.add_edge_list(transpose(nonzero(a)))
> 
> This should be much faster than the Python loop above.
> 

Do you think it would make sense then to have something analogous for
PropertyMaps?

Like:

pm.set_from_list(a)

in place of:

for v in g.vertices():
    pm[v] = a[i]

if pm is a property for vertices, and

for e in g.edges():
    pm[e] = a[i]

if it is for edges?

Pietro






More information about the graph-tool mailing list