Pytorch Geometric sparse adjacency matrix to edge index tensor

Viewed 2317

My data object has the data.adj_t parameter, giving me the sparse adjacency matrix. How can I get the edge_index tensor of size [2, num_edges] from this?

1 Answers

As you can see in the docs:

Since this feature is still experimental, some operations, e.g., graph pooling methods, may still require you to input the edge_index format. You can convert adj_t back to (edge_index, edge_attr) via:

row, col, edge_attr = adj_t.t().coo()
edge_index = torch.stack([row, col], dim=0)
Related