dgl.DGLHeteroGraph.out_degrees

DGLHeteroGraph.out_degrees(u='__ALL__', etype=None)[source]

Return the out-degrees of nodes u with edges of type etype.

Parameters:
  • u (list, tensor) – The node ID array of source type. Default is to return the degrees of all the nodes.
  • 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:

d – The out-degree array. d[i] gives the out-degree of node u[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.out_degrees(0, 'plays')
tensor([1])
>>> g.out_degrees(etype='follows')
tensor([1, 2, 0])

See also

out_degree()