I have a protein-protein interaction graph of ~100 nodes and ~1000 edges as a networkx graph. The nodes of the graph have string labels. When I use the function dgl.from_networkx(nx_g)
I understand the dgl uses node names starting from 0
. However, I see that the adjacency matrix generated by the dgl graph is different from the adjacency matrix generated from the networkx graph.
dgl_graph = dgl.from_networkx(nx_g) # nx_g is a networkx graph
dgl_adj = dgl_graph.adj().to_dense().numpy().astype(np.int32)
nx_adj = nx.to_numpy_array(nx_g).astype(np.int32)
print(nx_adj)
>>>
[[0 0 0 ... 0 0 0]
[0 0 0 ... 0 0 0]
[0 0 0 ... 0 0 0]
...
[0 0 0 ... 0 1 0]
[0 0 0 ... 1 0 0]
[0 0 0 ... 0 0 0]]
print(dgl_adj)
>>>
[[0 0 0 ... 1 1 0]
[0 0 0 ... 1 0 0]
[0 0 0 ... 0 0 1]
...
[1 1 0 ... 0 0 0]
[1 0 0 ... 0 0 0]
[0 0 1 ... 0 0 0]]
Why is this issue seen here? Though the graph is same, the ordering is totally different.
Also, is there a way to name the nodes of the dgl graph to strings?