Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot add edges or nodes using networkx

i am using python library networkx to create direct graph

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'

But, i acturally passed a tuple list as container of edges, and another list of int as container of nodes.

I print edges tuple list and nodes list I passed into methods and the error that shown as below:

enter image description here

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'

it's weried I can't figure out what's going wrong?

like image 851
Qin Avatar asked Oct 17 '25 14:10

Qin


1 Answers

You never created a graph because you never called the constructor. Must be:

graph = nx.DiGraph() # Note the ()!
like image 85
DYZ Avatar answered Oct 20 '25 02:10

DYZ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!