### How to obtain the resistance distance matrix of a graph?

I tried to compute resistance distance matrix of a graph g by first evaluating the Moore-Penrose inverse of the Laplacian matrix, but the result is not accurate, the entries are slightly different. I tried with the following algorithm.

L=g.laplacian_matrix()
from scipy import linalg
M=matrix(linalg.pinv(L))
R=matrix(QQ, g.order())
for i in range(g.order()):
for j in range(g.order()):
if i!=j:
R[i,j]=M[i,i]+M[j,j] -M[i,j]-M[j,i]