dgl.DGLGraph.node_attr_schemes

DGLGraph.node_attr_schemes(ntype=None)[source]

Return the node feature schemes for the specified type.

The scheme of a feature describes the shape and data type of it.

Parameters:

ntype (str, optional) – The node type name. Can be omitted if there is only one type of nodes in the graph.

Returns:

A dictionary mapping a feature name to its associated feature scheme.

Return type:

dict[str, Scheme]

Examples

The following example uses PyTorch backend.

>>> import dgl
>>> import torch

Query for a homogeneous graph.

>>> g = dgl.graph((torch.tensor([0, 1]), torch.tensor([1, 2])))
>>> g.ndata['h1'] = torch.randn(3, 1)
>>> g.ndata['h2'] = torch.randn(3, 2)
>>> g.node_attr_schemes()
{'h1': Scheme(shape=(1,), dtype=torch.float32),
 'h2': Scheme(shape=(2,), dtype=torch.float32)}

Query for a heterogeneous graph of multiple node types.

>>> g = dgl.heterograph({('user', 'plays', 'game'):
...                      (torch.tensor([1, 2]), torch.tensor([3, 4]))})
>>> g.nodes['user'].data['h1'] = torch.randn(3, 1)
>>> g.nodes['user'].data['h2'] = torch.randn(3, 2)
>>> g.node_attr_schemes('user')
{'h1': Scheme(shape=(1,), dtype=torch.float32),
 'h2': Scheme(shape=(2,), dtype=torch.float32)}