How to remove isolated nodes in a DGL graph?

I couldn’t find in the documentation how to do this, basically i have a dataset of DGL graphs, and i need to remove the isolated nodes in each graph, how to achieve this?

If the “isolated nodes” you referred to means nodes w/o in degrees and out degrees. Then the following code should work:

isolated_nodes = ((g.in_degrees() == 0) & (g.out_degrees() == 0)).nonzero().squeeze(1)
g.remove_node(isolated_nodes).
2 Likes