I wanted to calculate the sum of 1st to K-th power of an array and equally calculate the sum of 1st to k-th power of a tensor. I found out that the following codes and their results are totally different and I don’t know why.
I debugged the code and I know that the results are equal in the first round.
Numpy code:
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 code:
adj_k_prob = adj_prob_tensor
adj_k_pow = adj_prob_tensor
for i in range(K):
    adj_k_pow = torch.matmul(adj_prob_tensor, adj_k_pow)
    adj_k_prob += adj_k_pow