简体   繁体   English

无法使用networkx添加边或节点

[英]cannot add edges or nodes using networkx

i am using python library networkx to create direct graph 我正在使用python库networkx创建直接图

graph = nx.DiGraph
graph.add_edges_from(edges)
graph.add_nodes_from(isolated_nodes)

nothing went wrong until yesterday, add i got error below: 直到昨天什么都没出错,再加上以下错误:

TypeError: add_edges_from() missing 1 required positional argument: 'ebunch' TypeError:add_edges_from()缺少1个必需的位置参数:'ebunch'

But, i acturally passed a tuple list as container of edges, and another list of int as container of nodes. 但是,我实际通过了一个元组列表作为边的容器,并传递了另一个int列表作为节点的容器。

I print edges tuple list and nodes list I passed into methods and the error that shown as below: 我打印了传递给方法的边元组列表和节点列表,并显示了如下所示的错误:

在此处输入图片说明

so to simplify the problem, i test to add one edge or one node like below: 为了简化问题,我测试添加一个边或一个节点,如下所示:

graph.add_edge(1,2)
graph.add_node(3)

and I still got 而且我仍然

TypeError: add_edge() missing 1 required positional argument: 'v', or add_node() missing 1 required positional argument: 'n' TypeError:add_edge()缺少1个必需的位置参数:'v',或add_node()缺少1个必需的位置参数:'n'

it's weried I can't figure out what's going wrong? 感到疲倦的是我不知道出了什么问题?

You never created a graph because you never called the constructor. 您从未创建图,因为您从未调用过构造函数。 Must be: 一定是:

graph = nx.DiGraph() # Note the ()!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM