从 python 集合类型构造图
简单的问题是,是否有一个独立的函数可以从 python 集合的集合中制作图表? 更长的问题:我有几套Python。它们各自重叠或者有些是其他的子集。我想制作一个图表(如节点和边),节点是集合中的元素。边是集合的交集,并按集合交集中的元素数量加权。 python 有几个绘图包。 (NetworkX,igraph,...)我不熟悉其中任何一个的使用。他们中的任何一个都会直接从集合列表中制作图形,即 MakeGraphfromSets(alistofsets) 如果没有,您是否知道如何使用集合列表来定义边缘的示例。实际上看起来可能很简单,但有一个例子总是好的。
The short question, is there an off the self function to make a graph from a collection of python sets?
The longer question: I have several python sets. They each overlap or some are sub sets of others. I would like to make a graph (as in nodes and edges) nodes are the elements in the sets. The edges are intersection of the sets with weighted by number of elements in the intersection of the sets. There are several graphing packages for python. (NetworkX, igraph,...) I am not familiar with the use of any of them. Will any of them make a graph directly from a list of sets ie, MakeGraphfromSets(alistofsets)
If not do you know of an example of how to take the list of sets to define the edges. It actually looks like it might be straight forward but an example is always good to have.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
自己编写代码并不难:
此函数使用
sets
中的索引对每个集合进行编号。我们这样做是因为字典键必须是不可变的,这对于整数来说是正确的,但对于集合则不然。这是如何使用此函数的示例及其输出:
It's not too hard to code yourself:
This function numbers each set with its index within
sets
. We do this because dict keys must be immutable, which is true of integers but not sets.Here's an example of how to use this function, and it's output:
输出:
OUTPUT: