Set community index as a vertex attribute with IGraph Python -


when detect communities on graph igraph in python, result this:

print g.community_multilevel(return_levels=false)  clustering 100 elements , 4 clusters [0] 16, 17, 18, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,     36, 37, 39, 40, 44 [1] 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 19, 38, 92, 94, 96,     97, 98, 99 [2] 42, 43, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,     61, 62, 63, 64, 66, 67, 69 [3] 21, 41, 65, 68, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,     84, 85, 86, 87, 88, 89, 90, 91, 93, 95 

i'm adding corresponding community number attribute each vertex this:

for v in g.vs():     c = 0     in g.community_multilevel(return_levels=false):         if v.index in i:             print v.index,i,c             v["group"] = c         c += 1 

is there more elegant way achieve this?

what doing terribly inefficient because running community detection algorithm every single iteration of outer loop though result should same no matter how many times run it. simpler way be:

cl = g.community_multilevel(return_levels=false) g.vs["group"] = cl.membership 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -