[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] add vertex and set its attribute
From: |
Tamas Nepusz |
Subject: |
Re: [igraph] add vertex and set its attribute |
Date: |
Tue, 18 Jan 2011 15:38:19 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101208 Lightning/1.0b2 Thunderbird/3.1.7 |
len(g.vs(type=0)) or len(g.vs.select(type=0)) is the way to go.
--
Tamas
On 01/18/2011 03:35 PM, Simone Gabbriellini wrote:
> thanks Tamas,
>
> it works perfectly! May I ask a last t one last thing, how can I find the
> vcount() for each set? I am trying something like:
>
> len(g.vs("type"==0))
>
> but I'm afraid this is neither the right nor the smartest way...
>
> best regards,
> Simone
>
> Il giorno 18/gen/2011, alle ore 14.12, Tamas Nepusz ha scritto:
>
>>> Is there a single line code I can use for this or should I recover the
>>> vertex by its id, which I suppose will be the larger in the graph?
>> THe ID of the newly added vertex should be the largest in the graph,
>> so you can use that. Alternatively, you can create a helper method:
>>
>> def add_vertex_with_attrs(graph, attrs):
>> n = graph.vcount()
>> graph.add_vertices(1)
>> for key, value in attrs.iteritems():
>> graph.vs[n][key] = value
>>
>> Then you can simply call:
>>
>> add_vertex_with_attrs(graph, {"type": 0})
>>
>> --
>> Tamas
>>
>> _______________________________________________
>> igraph-help mailing list
>> address@hidden
>> http://lists.nongnu.org/mailman/listinfo/igraph-help
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help
>