Your dist
matrix already seems to be calculated correctly, but your first
matrix additions seem to have a problem with zero-cost edges.
See this slightly modified python version of your code, which uses 0.01
as cost for all self-edges and other 0-cost edges.
That code outputs the (hopefully) correct dist
and first
matrices
[0.01, inf, inf, 0.01, 0.01, inf]
[0.02, 0.01, 0.01, 0.01, 0.03, 0.02]
[0.01, inf, 0.01, 0.02, 0.02, 0.01]
[ inf, inf, inf, 0.01, inf, inf]
[0.01, inf, inf, 0.02, 0.01, inf]
[0.02, inf, 0.01, 0.01, 0.03, 0.01]
and
[ 0, None, None, 3, 4, None]
[ 2, 1, 2, 3, 2, 2]
[ 0, None, 2, 5, 0, 5]
[None, None, None, 3, None, None]
[ 0, None, None, 0, 4, None]
[ 2, None, 2, 3, 2, 5]