Ask Your Question

Revision history [back]

If you want exact results, you would better use exact pseudo inverse instead of scipy

sage: g = graphs.GridGraph((3,2))
sage: L = g.laplacian_matrix()
sage: L.pseudoinverse()   # exact version
[ 83/180  17/180  -1/180 -19/180 -37/180 -43/180]
[ 17/180  83/180 -19/180  -1/180 -43/180 -37/180]
[ -1/180 -19/180  47/180  -7/180  -1/180 -19/180]
[-19/180  -1/180  -7/180  47/180 -19/180  -1/180]
[-37/180 -43/180  -1/180 -19/180  83/180  17/180]
[-43/180 -37/180 -19/180  -1/180  17/180  83/180]
sage: matrix(linalg.pinv(L))    # floating point version
[     0.461111111111111    0.09444444444444366 -0.0055555555555548185   -0.10555555555555467   -0.20555555555555652    -0.2388888888888887]
[   0.09444444444444444    0.46111111111111003   -0.10555555555555454  -0.005555555555554606   -0.23888888888889012    -0.2055555555555555]
[ -0.005555555555555647   -0.10555555555555535     0.2611111111111109   -0.03888888888888898 -0.0055555555555552305    -0.1055555555555554]
[  -0.10555555555555546  -0.005555555555555619   -0.03888888888888879    0.26111111111111107   -0.10555555555555557  -0.005555555555555813]
[   -0.2055555555555557   -0.23888888888888798  -0.005555555555556556   -0.10555555555555653     0.4611111111111124    0.09444444444444448]
[   -0.2388888888888887   -0.20555555555555471   -0.10555555555555617  -0.005555555555556528    0.09444444444444547    0.46111111111111075]

Scipy is using floating point arithmetic. It makes it fast but approximative.