dgl.transform.khop_adj

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

Return the matrix of \(A^k\) where \(A\) is the adjacency matrix of \(g\), where a row represents the destination and a column represents the source.

Parameters:
Returns:

The returned tensor, dtype is np.float32.

Return type:

tensor

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_adj(g, 1)
tensor([[1., 0., 0., 0., 1.],
        [1., 1., 0., 0., 0.],
        [0., 1., 1., 0., 0.],
        [0., 0., 1., 1., 0.],
        [0., 0., 0., 1., 1.]])
>>> dgl.khop_adj(g, 3)
tensor([[1., 0., 1., 3., 3.],
        [3., 1., 0., 1., 3.],
        [3., 3., 1., 0., 1.],
        [1., 3., 3., 1., 0.],
        [0., 1., 3., 3., 1.]])