An edge_index is a two-row sparse tensor that records graph connectivity: the first row stores each edge's source node and the second stores its destination node. In PyTorch Geometric, its shape is [2, num_edges]. section 11.4 section 11.5.5
This representation supports graph neural network processing by:
- Storing only existing connections instead of a mostly empty dense adjacency matrix. section 11.5.5
- Allowing message-passing layers to find each node's neighbors and aggregate their features. section 11.4
- Representing directed entries explicitly; an undirected bond can therefore appear in both directions. section 11.5.5
Molecule graph in PyTorch Geometric
A molecule with 20 atoms and 25 bonds can use 20 node-feature rows. With bidirectional bonds and self-loops, edge_index may have shape 2×75: 50 directed bond entries plus 20 self-loop entries. section 11.5.5
from torch_geometric.data import Data
GCNData_mol = Data(
x=torch.Tensor(features),
edge_index=torch.LongTensor(edge_index).transpose(1, 0),
y=torch.FloatTensor([affinity_value])
)Constructs a PyTorch Geometric Data object with node features, a transposed edge_index tensor, and a graph-level affinity target. section 11.5.5

