I'd like to use the "add_edge_list" function to add edges to my graph, and simultaneously assign a value for an edge property map for each of the added edges.
When I try the following example (with no edge property map information) works fine:
elist1 = np.array([[0,1], [1, 2]]) #edge list with no value for edge property map data (only the source and target for the edges) g = gt.Graph() my_eprop = g.new_edge_property('bool') g.add_edge_list(elist)
But with the following example, I get the error below:
elist2 = np.array([[0,1, 1], [1, 2, 0]]) #edge list with edge property map value in 3rd column g = gt.Graph() my_eprop = g.new_edge_property('bool') g.add_edge_list(elist2, eprops=my_eprop)
Error:
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-48-6a949ea52c9b> in <module>() ----> 1 g.add_edge_list(elist2, eprops=my_eprop)
/usr/lib/python2.7/dist-packages/graph_tool/__init__.pyc in add_edge_list(self, edge_list, hashed, string_vals, eprops) 1969 eprops = () 1970 else: -> 1971 convert = [_converter(x.value_type()) for x in eprops] 1972 eprops = [_prop("e", self, x) for x in eprops] 1973 if not isinstance(edge_list, numpy.ndarray):
/usr/lib/python2.7/dist-packages/graph_tool/__init__.pyc in __getitem__(self, k) 534 kt = "Graph" 535 raise ValueError("invalid key '%s' of type '%s', wanted type: %s" --> 536 % (str(k), str(type(k)), kt) ) 537 538 def __setitem__(self, k, v):
ValueError: invalid key '0' of type '<type 'int'>', wanted type: Edge ---------------------------------------------------------------------------
Please help!
-- View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/... Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com.
On 27.03.2016 07:08, JHickey wrote:
But with the following example, I get the error below:
elist2 = np.array([[0,1, 1], [1, 2, 0]]) #edge list with edge property map value in 3rd column g = gt.Graph() my_eprop = g.new_edge_property('bool') g.add_edge_list(elist2, eprops=my_eprop)
The 'eprops' parameter expects a list. The last line should have been:
g.add_edge_list(elist2, eprops=[my_eprop])
Best, Tiago
Thanks!
On Sun, Mar 27, 2016 at 6:11 PM, Tiago de Paula Peixoto tiago@skewed.de wrote:
On 27.03.2016 07:08, JHickey wrote:
But with the following example, I get the error below:
elist2 = np.array([[0,1, 1], [1, 2, 0]]) #edge list with edge property
map
value in 3rd column g = gt.Graph() my_eprop = g.new_edge_property('bool') g.add_edge_list(elist2, eprops=my_eprop)
The 'eprops' parameter expects a list. The last line should have been:
g.add_edge_list(elist2, eprops=[my_eprop])
Best, Tiago
-- Tiago de Paula Peixoto tiago@skewed.de
graph-tool mailing list graph-tool@skewed.de http://lists.skewed.de/mailman/listinfo/graph-tool
Sir,
How to add multiple edge properties? If my_eprop and other_eprop are two arrays of edge properties and there is another column of values in elist2, then
g.add_edge_list(elist2,eprops=[my_eprop,other_eprop])
Is this correct or not?
This doesn't give any error but it takes only the second property column from elist2 while ignores the first one.
-- Sent from: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/
Am 27.09.18 um 07:36 schrieb ashutosh:
Sir,
How to add multiple edge properties? If my_eprop and other_eprop are two arrays of edge properties and there is another column of values in elist2, then
g.add_edge_list(elist2,eprops=[my_eprop,other_eprop])
Is this correct or not?
This doesn't give any error but it takes only the second property column from elist2 while ignores the first one.
If you want us to understand the problem you are having, you must provide a minimal and self-contained example that shows it, otherwise there is little we can do.
Best, Tiago
I have a data frame where I have five columns. First two columns are the source and sink nodes of interaction while the other three columns are three kinds of edge properties.
*import pandas as pd import graph_tool as gt
df = pd.DataFrame({'S':['a','b','c'], 'D':['b','c','a'], 'w1':[0.2,0.5,0.6], 'w2':[0.4,0.55,0.99], 'w3':[1,3,5]})
g = gt.Graph()
eprop1 = g.new_edge_property('float') eprop2 = g.new_edge_property('float') eprop3 = g.new_edge_property('int')*
Now if I want to add this to the properties to my network then
*g.edge_properties['eprop1'] = eprop1 g.edge_properties['eprop2'] = eprop2 g.edge_properties['eprop3'] = eprop3 *
and to assign values to the edge properties to the network I can write the command
*g.add_edge_list(df.values.tolist(),hashed=True, string_vals=True,eprops=[eprop1]) *
My question is: *'How do I assign values to the other two edge properties eprop2 and eprop3 from the DataFrame columns ?*
Something like, I guess:
*g.add_edge_list(df.values.tolist(),hashed=True, string_vals=True,eprops=[eprop1,eprop2,eprop3]) *
I tried this but it doesn't work.
-- Sent from: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/
Am 27.09.18 um 11:02 schrieb ashutosh:
Something like, I guess:
*g.add_edge_list(df.values.tolist(),hashed=True, string_vals=True,eprops=[eprop1,eprop2,eprop3])
I tried this but it doesn't work.
This works perfectly for me. In fact, the version with eprops=[eprop1] does not work, as the number of columns is unmatched.
What version of graph-tool are you using?
Best, Tiago
Its' working when I changed the edge property type 'int' to 'float' for the last one.
Also, the assigned property values are reversed in order when I tried the same for another example with only two property maps.
So for now, the problem seems to have solved.
Graph Tool version is 2.27
-- Sent from: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/
Am 27.09.18 um 15:03 schrieb ashutosh:
Its' working when I changed the edge property type 'int' to 'float' for the last one.
I can't reproduce this. The example you gave works as expected, regardless of the property type.
Note that so far you have not produced a minimal example that even allegedly reproduces the problem you are encountering. For some reason you gave us an example that _works_ instead of one that doesn't. Could you please provide a complete and minimal example that _shows_ the problem, i.e. gives the wrong output?
Also, the assigned property values are reversed in order when I tried the same for another example with only two property maps.
I can't reproduce this either. And as already explained many times, it is useless to mention problems without a reproducible example.
So for now, the problem seems to have solved.
???
If the problems you mention are really there, then they need to be fixed. I ask of you to please produce a minimal and complete example for them.
Best, Tiago
*import graph_tool as gt
netCoex = gt.Graph() *#create a network * coeff_prop = netCoex.new_edge_property("float") *# create a network edge property *pvals_prop = netCoex.new_edge_property("float")*
*netCoex.edge_properties['coeff'] = coeff_prop netCoex.edge_properties['pvals'] = pvals_prop*
*var = [['a','b','c','d','e'],['b','c','a','e','b'],[0.33,0.55,0.76,0.87,0.55],[0.12,0.012,0.004,0.0021,0.03]]
dfConet = pd.DataFrame({ 'Node1' : var[0], 'Node2' : var[1],'PearCoeff' : var[2], 'PVal' : var[3]})*
# Because you have two extra columns in the dataframe so you must pass two lists to the eprops argument
#Also for two properties it adds property values in reverse order. Why this is the problem ? # I defined coeff_prop first and pvals_prop later. But it doesn't reads the columns in this order.
#So variable added first (coeff_prop) is # assigned the last column and vice versa for the other variable pvals_prop
*coeffProp = netCoex.add_edge_list(dfConet.values.tolist(),hashed=True, string_vals=True,eprops=[pvals_prop,coeff_prop])*
-- Sent from: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/