Get Node list of a subgraph

Hi all, I am a new here. Thanks for the great tool.

I am wondering if there is any concise way to get the node list (with the full graph’s node index) of a subgraph (heteograph). For example, I got a subgraph “kg_1” from “kg” via the following script:

kg_1 = dgl.sampling.sample_neighbors(kg, node_dict, fanout=16)

I want to get the node list of “kg_1”. My current implementation is to get the edge list by

kg_1.edata[dgl.EID][etype]

And then get the node list using find_edges for each edge type from the full graph “kg”

kg.find_edges(eids, etype)

Any better way to do this? I tried g.ndata[dgl.NID], but returned empty dictionary.

Thanks.

Zipei Fan

sample_neighbors does not relabel the nodes, meaning that the nodes from the original graph are still there after picking the edges (even if they are isolated). You can use compact_graphs to remove all the isolated nodes. There you can get the node IDs using ndata[dgl.NID].

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.