Hi,

sorry for my naive question. I'd like to import hundreds of large and dense adjacency matrices available as a numpy arrays into graph_tool.

The following option takes very long. Q1: Is there a preferable alternative?

import graph_tool.all as gt
import numpy as np

adj=np.array([[1,1,0],[1,1,0],[0,0,1]])
n_vertices=adj.shape[0]

g = gt.Graph(directed=False)
vlist = g.add_vertex(n_vertices)

edge_ids = np.where(adj !=0)
for i in range(edge_ids[0].shape[0]):
    g.add_edge(g.vertex(edge_ids[0][i]), g.vertex(edge_ids[1][i]))

Since I am dealing with undirected graphs without selfloops a first step would be to take only one triangle of the symmetric adjacency matrix:

# get ids of upper triangle
upper_tr = np.triu_indices_from(np.zeros((n_vertices,n_vertices)))
adj[a[0],a[1]] = 0

...

Q2: is this a valid approach?

Thanks in advance,
 Matthias