# Revision history [back]

### 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]

 2 None vdelecroix 6314 ●16 ●68 ●133 http://www.labri.fr/pe...

### 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]-M[i,j]-M[j,i]