One simple solution is to just assign the 'weight' key.
In [1]: import networkx
In [2]: G=networkx.Graph()
In [3]: G.add_edge(0,1,a=2,b=4)
In [4]: G.edges(data=True)
Out[4]: [(0, 1, {'a': 2, 'b': 4})]
In [5]: for u,v,d in G.edges(data=True):
...: G[u][v]['weight']=d['b']
...:
...:
In [6]: G.edges(data=True)
Out[6]: [(0, 1, {'a': 2, 'b': 4, 'weight': 4})]
In [7]: for u,v,d in G.edges(data=True):
G[u][v]['weight']=d['a']
...:
...:
In [9]: G.edges(data=True)
Out[9]: [(0, 1, {'a': 2, 'b': 4, 'weight': 2})]
Aric
Do you have most updated SVN version of NetworkX installed? The above
error suggests that you have an older version.
Chris
The version in the Ubuntu repositories is quite old, at least in
comparison to what is on SVN. The new features you are trying to use
require a newer version (something like 1.0rc1). You might try
installing from SVN or easy_install.
Chris
This is working for me with 1.0rc1. Are you sure you are using
that version? If there is a bug here I'd like to get it fixed.
In [1]: import networkx;networkx.__version__
Out[1]: '1.0rc1'
In [2]: import pygraphviz;pygraphviz.__version__
Out[2]: '1.0.dev1489'
In [3]: G=networkx.Graph()
In [4]: G.add_edge(1,2,weight=7)
In [5]: A=networkx.to_agraph(G)
In [6]: A
Out[6]:
strict graph {
1 -- 2 [weight=7];
}
In [7]: pos=networkx.pygraphviz_layout(G)
In [8]: pos
Out[8]: {1: (28.0, 29.0), 2: (100.0, 19.0)}
Aric