You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
multigraph remove edge with a key doesn't work (migrated from Trac #326) #323
Hello,
When i run the code piece below, i got this error :
G.add_edge(1,2,key='first')
TypeError: add_edge() got an unexpected keyword argument 'key'
G = nx.MultiGraph()[[BR]]
G.add_edge(1,2,key='first')[[BR]]
G.add_edge(1,2,key='second')[[BR]]
G.remove_edge(1,2,key='second')[[BR]]
And when i run the code below:[[BR]]
G = nx.MultiGraph() [[BR]]
G.edges(data=True)[[BR]]
G.add_edge(1,2,data='first')[[BR]]
G.add_edge(1,2,data='second')[[BR]]
G.remove_edge(1,2,data='second')[[BR]]
the program deletes both edges between nodes 1 and 2.. how can i remove just the edge labelled with 'second' key..
Which version of NetworkX are you using?
This works with the latest development version.
'''
In [18]: G = nx.MultiGraph()
In [19]: G.add_edge(1,2,key='first')
In [20]: G.add_edge(1,2,key='second')
In [21]: G.remove_edge(1,2,key='second')
In [22]: G.edges(keys=True)
Out[22]: [(1, 2, 'first')]
'''
'''
In [24]: nx.version
Out[24]: '1.1.dev1553'
'''
In the second question you will need to specify the key explicitly
when you remove the edge even though you didn't when you added the edge.
The default is to number the edges with integer keys starting at 0.
'''
In [25]: G = nx.MultiGraph()
Activity
networkx-trac commentedon Jul 20, 2012
Comment in Trac by @hagberg, 2010-03-19
Which version of NetworkX are you using?
This works with the latest development version.
'''
In [18]: G = nx.MultiGraph()
In [19]: G.add_edge(1,2,key='first')
In [20]: G.add_edge(1,2,key='second')
In [21]: G.remove_edge(1,2,key='second')
In [22]: G.edges(keys=True)
Out[22]: [(1, 2, 'first')]
'''
'''
In [24]: nx.version
Out[24]: '1.1.dev1553'
'''
In the second question you will need to specify the key explicitly
when you remove the edge even though you didn't when you added the edge.
The default is to number the edges with integer keys starting at 0.
'''
In [25]: G = nx.MultiGraph()
In [26]: G.edges(data=True)
Out[26]: []
In [27]: G.add_edge(1,2,data='first')
In [28]: G.add_edge(1,2,data='second')
In [29]: G.edges(data=True,keys=True)
Out[29]: [(1, 2, 0, {'data': 'first'}), (1, 2, 1, {'data': 'second'})]
In [30]: G.remove_edge(1,2,key=1)
In [31]: G.edges(data=True,keys=True)
Out[31]: [(1, 2, 0, {'data': 'first'})]
'''
networkx-trac commentedon Jul 20, 2012
Comment in Trac by @hagberg, 2010-03-19