Adjacency Matrix to Edge Index (Solution)

Hey,

For those who have this question, here you have a way to solve it!

adj_t = torch.tensor([[0,1,0,0],[1,0,0,0], [1,0,0,1], [0,0,1,0]])
edge_index = adj_t.nonzero().t().contiguous()

>>> tensor([[0, 1, 2, 2, 3],
            [1, 0, 0, 3, 2]])

Thanks for your attention,
André Amaral

4 Likes