<p>二部图中的节点集是等价的(如果我使用了错误的术语,请纠正我的错误)-没有什么主要区别,哪一个命名为“top”和“bottom”。在</p>
<p>根据<a href="https://math.stackexchange.com/questions/1102592/choosing-which-sets-of-nodes-are-top-and-bottom-in-bipartite-graph-represent">Choosing which sets of nodes are 'top' and 'bottom' in bipartite graph representations of real-world complex networks. - Mathematics Stack Exchange</a>中的参考文献,对它们进行这样的分类是在特定应用中商定的惯例(为了一致性),而不是任何数学差异。所以,两个答案都是正确的。在</p>
<p>查看<code>networkx.algorithms.bipartite.sets</code>的源代码可以发现,它委托给<code>networkx.algorithms.bipartite.color</code>,后者依次迭代节点。在<code>for n in G</code>中排名第一的节点总是被赋予颜色<code>1</code>,并进入<code>sets</code>中的第一个集合:</p>
<pre><code>In [2]: x=(161,1),(589,2),(162,1),(163,1),(589,2)
In [4]: g=networkx.Graph(x)
In [8]: g2=networkx.Graph(((80,2),(589,2),(162,1),(163,1),(589,2)))
In [11]: [n for n in g]
Out[11]: [161, 2, 163, 1, 162, 589]
In [12]: [n for n in g2]
Out[12]: [1, 2, 163, 162, 589, 80]
In [14]: networkx.algorithms.bipartite.sets(g)
Out[14]: ({2, 161, 162, 163}, {1, 589})
In [13]: networkx.algorithms.bipartite.sets(g2)
Out[13]: ({1, 2}, {80, 162, 163, 589})
</code></pre>
<p>因此,如果你有一些特定的想法,一个节点的哪些属性应该归类为“top”/“bottom”,那么你需要把它实际编程到:</em>例如,看看结果,看看结果是什么。在</p>