Replies: 1 comment 2 replies
-
from torch_geometric.utils import degree, subgraph
deg = degree(data.edge_index[1], data.num_nodes)
mask = deg == 1
edge_index, edge_attr = subgraph(mask, data.edge_index, data.edge_attr, relabel_nodes=True, num_nodes=data.num_nodes)
data.x = data.x[mask]
data.edge_index = edge_index
data.edge_attr = edge_attr |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am parsing a knowledge graph and trying to build a small subgraph from it. After parsing I realized I have a lot of nodes with degree 1. I would ideally like to remove such nodes since they do not add much information. Is there a way of removing nodes with degree 1?
I know networkx has a function that can remove the nodes based on conditions. Hence, I convert my data into networkx and do the processing then convert it back to pytorch_geometric. I was wondering if there exists a simpler way for the same.
Beta Was this translation helpful? Give feedback.
All reactions