dgl.DGLGraph.edges

DGLGraph.edges

Return a edges view that can used to set/get feature data.

>>> G = dgl.DGLGraph()
>>> G.add_nodes(3)
>>> G.add_edges([0, 1], 2)  # 0->2, 1->2

Get edges in graph G:

>>> G.edges()
(tensor([0, 1]), tensor([2, 2]))

Get feature dictionary of all edges:

>>> G.edges[:].data
{}

The above can be abbreviated as

>>> G.edata
{}

Init 2 edges with zero vector(len=4)

Note

Here we use pytorch syntax for demo. The general idea applies to other frameworks with minor syntax change (e.g. replace torch.tensor with mxnet.ndarray).

>>> import torch as th
>>> G.edata['y'] = th.zeros((2, 4))
>>> G.edata
{'y' : tensor([[0., 0., 0., 0.],
               [0., 0., 0., 0.]])}

Use G.edges to get/set features for some edges.

>>> G.edges[1, 2].data['y'] = th.ones((1, 4))
>>> G.edata
{'y' : tensor([[0., 0., 0., 0.],
               [1., 1., 1., 1.]])}