dgl.BatchedDGLHeteroGraph.batch_num_nodes

BatchedDGLHeteroGraph.batch_num_nodes(ntype=None)[source]

Return the numbers of nodes of the given type for all heterographs in the batch.

Parameters:ntype (str, optional) – The node type. Can be omitted if there is only one node type in the graph. (Default: None)
Returns:The ith element gives the number of nodes of the specified type in the ith graph.
Return type:list of int

Examples

>>> g1 = dgl.heterograph({
...      ('user', 'follows', 'user'): [(0, 1), (1, 2)],
...      ('user', 'plays', 'game'): [(0, 0), (1, 0), (2, 1), (3, 1)]
...      })
>>> g2 = dgl.heterograph({
...      ('user', 'follows', 'user'): [(0, 1), (1, 2)],
...      ('user', 'plays', 'game'): [(0, 0), (1, 0), (2, 1)]
...      })
>>> bg = dgl.batch_hetero([g1, g2])
>>> bg.batch_num_nodes('user')
[4, 3]
>>> bg.batch_num_nodes('game')
[2, 2]