dgl.DGLGraph.ntypesΒΆ

property DGLGraph.ntypesΒΆ

Return all the node type names in the graph.

Returns

All the node type names in a list.

Return type

list[str]

Notes

DGL internally assigns an integer ID for each node type. The returned node type names are sorted according to their IDs.

Examples

The following example uses PyTorch backend.

>>> 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.ntypes
['game', 'user']