dgl.transform.khop_graph

dgl.transform.khop_graph(g, k)[source]

Return the graph that includes all \(k\)-hop neighbors of the given graph as edges. The adjacency matrix of the returned graph is \(A^k\) (where \(A\) is the adjacency matrix of \(g\)).

Parameters:
  • g (dgl.DGLGraph) – The input graph.
  • k (int) – The \(k\) in k-hop graph.
Returns:

The returned DGLGraph.

Return type:

dgl.DGLGraph

Examples

>>> import dgl
>>> g = dgl.DGLGraph()
>>> g.add_nodes(5)
>>> g.add_edges([0,1,2,3,4,0,1,2,3,4], [0,1,2,3,4,1,2,3,4,0])
>>> dgl.khop_graph(g, 1)
DGLGraph(num_nodes=5, num_edges=10,
         ndata_schemes={}
         edata_schemes={})
>>> dgl.khop_graph(g, 3)
DGLGraph(num_nodes=5, num_edges=40,
         ndata_schemes={}
         edata_schemes={})