Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python networkx,有n个节点的图,每个节点有k度_Python_Graph_Networkx - Fatal编程技术网

python networkx,有n个节点的图,每个节点有k度

python networkx,有n个节点的图,每个节点有k度,python,graph,networkx,Python,Graph,Networkx,我试着写一个函数,它有两个参数:(节点的数量,每条边的度数)。这个函数应该用节点的数量构建一个图,每个节点都有边度。此功能无法正常工作,我需要帮助修复它,请帮助我: def k_degree_graph(amount_of_vertex, degree_of_vertex): global G degree_of_vertex-=1 G=nx.Graph() list_of_nodes = [i for i in range(1, amount_of_vertex

我试着写一个函数,它有两个参数:(节点的数量,每条边的度数)。这个函数应该用节点的数量构建一个图,每个节点都有边度。此功能无法正常工作,我需要帮助修复它,请帮助我:

def k_degree_graph(amount_of_vertex, degree_of_vertex):
    global G
    degree_of_vertex-=1
    G=nx.Graph()
    list_of_nodes = [i for i in range(1, amount_of_vertex + 1)]
    G.add_nodes_from(list_of_nodes)
    for i in range(1, amount_of_vertex + 1):
        for j in range(1, degree_of_vertex + degree_of_vertex%2):
            if i>j:
                buffer=(i, i-j)
            else:
                buffer=(i, i-j+amount_of_vertex)
            G.add_edge(*buffer)
    draw_graph()

顶点数量=10
顶点度=4
。然后手工计算出当
i=1
时嵌套for循环中会发生什么。
1
在其他什么时候会添加边缘?检查末尾的G.neights(1),以确保正确。这应该为正在发生的事情提供一个良好的开端。将有更干净的方法来完成那些嵌套的for循环。我不理解你的意思,我尝试使用邻居来调试这个函数,但是如果你调用
k_degree\u图(10,4)
并打印出
G.neights(1)
,最后你得到了什么?