NetworkX最大的连接组件共享属性
我知道存在计算NetworkX中图的连接组件的大小的功能。您可以将属性添加到节点。 在Axelrod用于传播培养物的模型中,一个有趣的测量是最大的连接组件的大小,其节点具有多个属性。在NetworkX中有办法做到这一点吗? 例如,假设我们通过网络代表人口。每个节点都有头发颜色和肤色的属性。如何获得节点中最大的组成部分的大小,以便在该子图中和每个节点具有相同的头发和肤色? 谢谢
I know there exist functions for computing the size of the connected components of a graph in NetworkX. You can add attributes to a node.
In Axelrod's model for dissemination of culture, an interesting measurement is the size of the largest connected component whose nodes share several attributes. Is there a way of doing that in NetworkX?
For example, let's say we have a population represented through a network. Each node has attributes of hair color and skin color. How can I get the size of the largest component of nodes such that in that subgraph each and every node has the same hair and skin color?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于一般数据分析,最好使用
pandas
。使用图形库,例如networkx
或Graph-tool
确定连接的组件,然后将该信息加载到您可以分析的dataframe
中。在这种情况下,PANDASgroupby
和nunique
(唯一元素的数量)功能将很有用。这是一个使用
graph-tool
的独立示例(使用此网络)。您也可以通过NetworkX
来计算连接的组件。打印以下内容:
For general data analysis, it's best to use
pandas
. Use a graph library likenetworkx
orgraph-tool
to determine the connected components, and then load that info into aDataFrame
that you can analyze. In this case, the pandasgroupby
andnunique
(number of unique elements) features will be useful.Here's a self-contained example using
graph-tool
(using this network). You could also compute the connected components vianetworkx
.That prints the following: