dgl.DGLHeteroGraph.in_degree

DGLHeteroGraph.in_degree(v, etype=None)[source]

Return the in-degree of node v with edges of type etype.

Parameters:
  • v (int) – The node ID of destination 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 in-degree.

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.in_degree(0, 'plays')
2
>>> g.in_degree(0, 'follows')
0

See also

in_degrees()