dgl.DGLHeteroGraph.out_degree

DGLHeteroGraph.out_degree(u, etype=None)[source]

Return the out-degree of node u with edges of type etype.

Parameters:
  • u (int) – The node ID of source type.
  • etype (str or tuple of str, optional) – The edge type. Can be omitted if there is only one edge type in the graph. (Default: None)
Returns:

The out-degree of node u with edges of type etype.

Return type:

int

Examples

Instantiate a heterograph.

>>> plays_g = dgl.bipartite([(0, 0), (1, 0), (1, 2), (2, 1)], 'user', 'plays', 'game')
>>> follows_g = dgl.graph([(0, 1), (1, 2), (1, 2)], 'user', 'follows')
>>> g = dgl.hetero_from_relations([plays_g, follows_g])

Query for node degree.

>>> g.out_degree(0, 'plays')
1
>>> g.out_degree(1, 'follows')
2

See also

out_degrees()