阅读 igraph for python 中的断开图
我想知道使用 python 的 igraph 读取不连续无向图的最佳方法。例如,如果我有一个简单的图,其中 0 链接到 1,而 2 是一个未连接到任何其他节点的节点。我无法让 igraph 从边缘列表格式(Graph.Read_Edgelist(...))读取它,因为每一行都必须是一条边缘,所以不允许以下内容:
0 1
2
我只是想知道邻接矩阵是否是我的在这种情况下唯一/最好的选择(我可以让它通过这个表示工作)?我更喜欢一种可以通过查看数据来理解数据的格式(对于矩阵格式来说,这确实很难)。
提前致谢!
I'd like to know the best way to read a disconected undirected graph using igraph for python. For instance, if I have the simple graph in which 0 is linked to 1 and 2 is a node not connected to any other. I couldn't get igraph to read it from a edgelist format(Graph.Read_Edgelist(...)), because every line must be an edge, so the following is not allowed:
0 1
2
I've been just wondering if adjacency matrix is my only/best option in this case (I could get it to work through this representation)? I'd rather a format in which I could understand the data by looking it (something really hard when it comes to matrix format).
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
LGL 格式允许孤立的顶点(请参阅 Graph.Read_LGL)。格式如下:
我想你已经明白了基本的想法;以哈希标记开头的行表示正在定义一个新节点。此后,这些行指定刚刚定义的节点的邻居。如果您需要一个孤立的节点,只需在该行中指定前面加上哈希标记的节点 ID,然后继续处理下一个节点。
有关 LGL 格式的更多信息可以在此处找到。
您可能想要检查的另一种相当可读的格式是 igraph 也支持的 GML 格式。
There's the LGL format which allows isolated vertices (see
Graph.Read_LGL
). The format looks like this:I think you get the basic idea; lines starting with a hash mark indicate that a new node is being defined. After this, the lines specify the neighbors of the node that has just been defined. If you need an isolated node, you just specify the node ID prepended by a hash mark in the line, then continue with the next node.
More information about the LGL format is to be found here.
Another fairly readable format that you might want to examine is the GML format which igraph also supports.