I’m so sorry for bothering you. The following code has problem. I would be grateful if you help me.
import networkx as nx
import numpy as np
import torch
from scipy import sparse


def sparse_mx_to_torch_sparse_tensor(sparse_mx):
    """Convert a scipy sparse matrix to a torch sparse tensor."""
    sparse_mx = sparse_mx.tocoo().astype(np.float32)
    indices = torch.from_numpy(
        np.vstack((sparse_mx.row, sparse_mx.col)).astype(np.int64))
    values = torch.from_numpy(sparse_mx.data)
    shape = torch.Size(sparse_mx.shape)
    return torch.sparse.FloatTensor(indices, values, shape)


if __name__ == '__main__':
    K = 5
    ### Load Data
    G = nx.karate_club_graph()
    G = nx.adj_matrix(G)
    adj_prob = G.toarray()
    adj_prob = adj_prob / adj_prob.sum(axis=1)[:, None]

    ### Numpy
    adj_k_prob = adj_prob
    adj_k_pow =  adj_prob
    for i in range(K):
        adj_k_pow = np.matmul(adj_prob, adj_k_pow)
        adj_k_prob += adj_k_pow


    ### Pytorch
    adj_prob_sparse = sparse.csr_matrix(adj_prob)
    adj_prob_tensor = sparse_mx_to_torch_sparse_tensor(adj_prob_sparse)

    adj_k_prob_tensor = adj_prob_tensor.to_dense().clone()
    adj_k_pow_tensor = adj_prob_tensor.to_dense().clone()

    for i in range(K):
        adj_k_pow_tensor = torch.matmul(adj_prob_tensor.to_dense(), adj_k_pow_tensor)
        adj_k_prob_tensor += adj_k_pow_tensor



    print(torch.abs(torch.from_numpy(adj_k_prob).double() - adj_k_prob_tensor.double()).max())