About graph vertex

User 2634 | 11/26/2015, 8:57:02 AM

I want to make the vertex attr have dict or list just like graph.vertices['label_dict'] = {1:0,2:0,3:0,4:0,5:0} or graph.vertices['label_list'] = [0,1,2,3]

but the data structure not allow that

Is there any way to make the attr be a list or dict?

Comments

User 1592 | 11/26/2015, 3:27:43 PM

You can edit an SFrame with the properties of the graph nodes and then do graph.add_vertices(data) that way the node data will be updated with the newer edited data.


User 2634 | 11/28/2015, 4:09:19 AM

Hi Danny,

sfvert = SFrame({'id': [0, 1, 2], 'breed':['lab', 'lab', 'vizsla']}) g = g.addvertices(sfvert, vidfield='id')

Is this you mean? but I need is like that:

 vertex_id     |      vertex_attr_dict	   |    vertex_attr_list
 1             |       {1:2,2:3,3:4}	   |    [1,2,3,4]
 2             |        {2:3,2:2}	       |    [4,2]

User 1178 | 11/28/2015, 7:44:12 PM

Hi Yuanqing,

We use SFrame as underneath structure to store SGraph, so you should be able to use any structure that SFrame supports. Here is a simple example:

`

sf = gl.SFrame({'id':[1,2,3], 'l':[[1],[1,2],[1,2,3]]}) g = gl.SGraph() g = g.addvertices(sf, vidfield='id') print g.get_vertices() +------+-----------------+ | __id | l | +------+-----------------+ | 2 | [1.0, 2.0] | | 3 | [1.0, 2.0, 3.0] | | 1 | [1.0] | +------+-----------------+ [3 rows x 2 columns]

`


User 2634 | 12/1/2015, 4:14:59 PM

get it. thank you!