How to convert adjacency matrix to edge_index format?

I have an adjaceny tensor

tensor([[0., 1., 1., 1.],
        [1., 0., 1., 1.],
        [1., 1., 0., 1.],
        [1., 1., 1., 0.]])

How can I convert it to the edge_index form used in pytorch geometric? Introduction by Example — pytorch_geometric 2.0.4 documentation The actual adjacency matrix is far larger so it’s not something I want to create manually.

2 Likes

I found a way to do it:

Hope it helps!