You can just use networkx.shortest_path(G)
with the weight='weight' keyword.
e.g.
In [1]: import networkx as nx
In [2]: G = nx.Graph()
In [3]: G.add_edge(1,2,weight=7)
In [4]: G.add_edge(1,4,weight=3)
In [5]: G.add_edge(2,3,weight=1)
In [6]: G.add_edge(3,4,weight=100)
In [7]: nx.adjacency_matrix(G).todense()
Out[7]:
matrix([[ 0, 7, 0, 3],
[ 7, 0, 1, 0],
[ 0, 1, 0, 100],
[ 3, 0, 100, 0]])
In [8]: nx.shortest_path_length(G)
Out[8]:
{1: {1: 0, 2: 1, 3: 2, 4: 1},
2: {1: 1, 2: 0, 3: 1, 4: 2},
3: {1: 2, 2: 1, 3: 0, 4: 1},
4: {1: 1, 2: 2, 3: 1, 4: 0}}
In [9]: nx.shortest_path_length(G,weight='weight')
Out[9]:
{1: {1: 0, 2: 7, 3: 8, 4: 3},
2: {1: 7, 2: 0, 3: 1, 4: 10},
3: {1: 8, 2: 1, 3: 0, 4: 11},
4: {1: 3, 2: 10, 3: 11, 4: 0}}
In [10]: nx.utils.dict_to_numpy_array(nx.shortest_path_length(G,weight='weight'))
Out[10]:
array([[ 0., 7., 8., 3.],
[ 7., 0., 1., 10.],
[ 8., 1., 0., 11.],
[ 3., 10., 11., 0.]])