dgl.DGLGraph.edge_attr_schemes
- DGLGraph.edge_attr_schemes(etype=None)[source]
返回指定类型的边缘特征方案。
特征的方案描述了它的形状和数据类型。
- Parameters:
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:
一个将特征名称映射到其相关特征方案的字典。
- Return type:
示例
以下示例使用PyTorch后端。
>>> import dgl >>> import torch
查询一个同构图。
>>> g = dgl.graph((torch.tensor([0, 1]), torch.tensor([1, 2]))) >>> g.edata['h1'] = torch.randn(2, 1) >>> g.edata['h2'] = torch.randn(2, 2) >>> g.edge_attr_schemes() {'h1': Scheme(shape=(1,), dtype=torch.float32), 'h2': Scheme(shape=(2,), dtype=torch.float32)}
查询具有多种边类型的异构图。
>>> g = dgl.heterograph({('user', 'plays', 'game'): ... (torch.tensor([1, 2]), torch.tensor([3, 4])), ... ('user', 'follows', 'user'): ... (torch.tensor([3, 4]), torch.tensor([5, 6]))}) >>> g.edges['plays'].data['h1'] = torch.randn(2, 1) >>> g.edges['plays'].data['h2'] = torch.randn(2, 2) >>> g.edge_attr_schemes('plays') {'h1': Scheme(shape=(1,), dtype=torch.float32), 'h2': Scheme(shape=(2,), dtype=torch.float32)}
另请参阅