dgl.DGLHeteroGraph.in_degrees

DGLHeteroGraph.in_degrees(v='__ALL__', etype=None)[source]

Return the in-degrees of nodes v with edges of type etype.

Parameters:
  • v (list, tensor, optional.) – The node ID array of the destination type. Default is to return the degrees of all nodes.
  • etype (str or tuple of str or None, optional) – The edge type. Can be omitted if there is only one edge type in the graph. (Default: None)
Returns:

d – The in-degree array. d[i] gives the in-degree of node v[i] with edges of type etype.

Return type:

tensor

Examples

The following example uses PyTorch backend.

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_degrees(0, 'plays')
tensor([2])
>>> g.in_degrees(etype='follows')
tensor([0, 1, 2])

See also

in_degree()