擅长:python、mysql、java
<p>请参阅networkx的<a href="https://networkx.github.io/documentation/latest/tutorial/tutorial.html#edge-attributes" rel="nofollow">tutorial</a>。在</p>
<pre><code>import networkx as nx
G = nx.Graph()
G.add_nodes_from([1, 2, 3, 4, 5])
G.add_edge(1, 2, weight=4.7 )
G.add_edges_from([(1,2), (2,3,{'weight':8})])
G[1][2]['weight'] = 4.7
G.edge[1][2]['weight'] = 4
</code></pre>
<p>在你的例子中</p>
^{pr2}$
<p>添加默认权重为1的所有边。在</p>