How to assign edge weights directly to a heterograph?

The configuration of my work as following:
dgl 0.7.2

The problem is that when I create a heterograph, I can feed dgl.heterograph() a data_dict, however, the data_dict is the information of the edge in the aspect of the node. Can I convey the weight feature of the edge in this data_dict? Or is there other more convienient ways to solve this need?

Part of the code is as follows:

import dgl
import numpy as np
import torch as th
from dgl.nn import EdgeWeightNorm, GraphConv
from collections import defaultdict
edge_wights = [0.1,0.3,0.004,0.5,1,0.7]
data_dict = defaultdict(list)
for i in range(6):
    data_dict[('h_type', i, 'h_type')].append((a[i],b[i]))

you can do g[‘0’].edata[‘eweight’] = edgeweight

Note that please use string as the etype and ntype name, not int

1 Like