dgl.DGLGraph.successors
- DGLGraph.successors(v, etype=None)[source]
返回具有指定边类型的特定节点的后继节点。
如果图中存在类型为
etype
的边(v, u)
,则节点u
是节点v
的后继节点。- Parameters:
v (int) – 节点ID。如果图有多个边类型,ID对应于边类型的源类型。
etype (str or (str, str, str), optional) –
The type names of the edges. The allowed type name formats are:
(str, str, str)
for source node type, edge type and destination node type.or one
str
edge type name if the name can uniquely identify a triplet format in the graph.
Can be omitted if the graph has only one type of edges.
- Returns:
v
的具有指定边类型的后继节点。- Return type:
张量
示例
以下示例使用PyTorch后端。
>>> import dgl >>> import torch
创建一个同构图。
>>> g = dgl.graph((torch.tensor([0, 0, 1, 1]), torch.tensor([1, 1, 2, 3])))
查询节点1。
>>> g.successors(1) tensor([2, 3])
对于具有多种边类型的图,需要在查询中指定边类型。
>>> hg = dgl.heterograph({ ... ('user', 'follows', 'user'): (torch.tensor([0, 1]), torch.tensor([1, 2])), ... ('user', 'plays', 'game'): (torch.tensor([3, 4]), torch.tensor([5, 6])) ... }) >>> hg.successors(1, etype='follows') tensor([2])
另请参阅