DGLGraph.add_edges(u, v, data=None)[source]

Add multiple edges for list of source nodes u and destination nodes v. A single edge is added between every pair of u[i] and v[i].

Parameters: u (list, tensor) – The source node IDs. All nodes must exist in the graph. v (list, tensor) – The destination node IDs. All nodes must exist in the graph. data (dict, optional) – Feature data of the added edges.

Notes

If new edges are added with features, and any of the old edges do not have some of the feature fields, those fields are filled by initializers defined with set_e_initializer (default filling with zeros).

Examples

The following example uses PyTorch backend.

>>> G = dgl.DGLGraph()
>>> G.add_edges([0, 2], [1, 3]) # add edges (0, 1) and (2, 3)


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