【dgl学习】dgl.canonical_etypes函数解析

该博客介绍了如何使用DGL库从异构图中获取规范化的边类型。`canonical_etypes`函数返回图中所有独特的三元组形式(源节点类型,边类型,目标节点类型),例如`('user','follows','user')`。示例展示了创建包含不同边类型的图,并调用`canonical_etypes`来列举所有边类型。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  函数功能:以三元组的形式返回图中定义的边。
下面是官方给出的解释

Return all the canonical edge types in the graph.

A canonical edge type is a string triplet (str, str, str) for source node type, edge type and destination node type.

Returns
All the canonical edge type triplets in a list.

Return type
list[(str, str, str)]

举个例子

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.canonical_etypes

[('user', 'follows', 'user'),
 ('user', 'follows', 'game'),
 ('user', 'plays', 'game')]

参考文献

[1]dgl.DGLGraph.canonical_etypes

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值