dgl.DGLGraph.etypes
- property DGLGraph.etypes
返回图中所有边的类型名称。
注意事项
DGL 内部为每种边类型分配一个整数 ID。返回的边类型名称按照其 ID 排序。
指定关系的完整格式是一个字符串三元组
(str, str, str)
,分别表示源节点类型、边类型和目标节点类型。DGL 将此格式称为 规范边类型。一个边类型可以出现在多个规范边类型中。例如,'interacts'
可以出现在两个规范边类型('drug', 'interacts', 'drug')
和('protein', 'interacts', 'protein')
中。另请参阅
示例
以下示例使用 PyTorch 后端。
>>> import dgl >>> import torch
>>> g = dgl.heterograph({ ... ('user', 'follows', 'user'): (torch.tensor([0, 1]), torch.tensor([1, 2])), ... ('user', 'follows', 'game'): (torch.tensor([0, 1, 2]), torch.tensor([1, 2, 3])), ... ('user', 'plays', 'game'): (torch.tensor([1, 3]), torch.tensor([2, 3])) ... }) >>> g.etypes ['follows', 'follows', 'plays']