英文:
What is an iterable of networkx graphs?
问题
我正在尝试使用nx.compose_all()
将30个图组合成一个图。
根据文档,输入必须是一个"networkx图的可迭代对象"。我不确定这是什么意思 - 一个图列表似乎不是Python可以构建的东西?
如果有人可以解释什么是可迭代的图对象以及如何获取一个,那将非常好。
我已经在Google上搜索了"iterable over networkx graphs",但没有找到有效的结果。
英文:
I am trying to compose 30 graphs into one graph, using nx.compose_all().
The input according to documentation must be an 'iterable over networkx graphs' object. I'm unsure what this means - a list of graphs doesn't seem to be something Python can build?
If someone can explain what an iterable over graph objects is and how to get one that would be great.
I've searched through google for 'iterable over networkx graphs' but nothing valid comes back.
答案1
得分: 0
在Python中,可迭代对象是指能够逐个返回其成员的任何对象。常见的示例包括列表、元组、字符串、字典和集合。当文档提到“在networkx图上可迭代”时,它简单地意味着一组networkx图形的集合,您可以对其进行循环。
例如,如果您有多个图形,如G1、G2、...、G30,您可以将它们放入一个列表中,并将其作为nx.compose_all()的参数使用。
import networkx as nx
# 创建多个图形
G1 = nx.Graph()
G1.add_edge('a', 'b')
G2 = nx.Graph()
G2.add_edge('b', 'c')
G3 = nx.Graph()
G3.add_edge('c', 'd')
# 将它们放入一个列表
graphs = [G1, G2, G3]
# 使用列表作为nx.compose_all的参数
G_all = nx.compose_all(graphs)
英文:
An iterable in Python is any object capable of returning its members one at a time. Common examples include lists, tuples, strings, dictionaries, and sets. When the documentation mentions an "iterable over networkx graphs", it simply means a collection of networkx graphs that you can loop over.
For example, if you have multiple graphs like G1, G2, ..., G30, you could put them into a list and use that as an argument for nx.compose_all()
import networkx as nx
# Creating multiple graphs
G1 = nx.Graph()
G1.add_edge('a', 'b')
G2 = nx.Graph()
G2.add_edge('b', 'c')
G3 = nx.Graph()
G3.add_edge('c', 'd')
# Put them into a list
graphs = [G1, G2, G3]
# Use the list as an argument for nx.compose_all
G_all = nx.compose_all(graphs)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论