1

I am using the networkx library, more specifically the girvan_newman algorithm from nextworkx.algorithms.community.centrality on a data set of about 1200 vertices each with 1-10 edges between them. When I run the below code I only see two communities

ret = girvan_newman(G)
tuple(sorted(c) for c in next(ret))

I want to see it broken down further. I then tried

import itertools
limited=itertools.takewhile(lambda c: len(c) <= 20, ret)
for communities in limited:
  print(tuple(sorted(c) for c in communities))

but the output is empty and I'm not sure what I'm doing wrong.

I also can't figure out how to access the lists of communities to put into a dataframe, not just print them.

Any help is appreciated!

John Smith
  • 291
  • 2
  • 12
  • [Girvan-Newman algorithm](https://en.wikipedia.org/wiki/Girvan%E2%80%93Newman_algorithm) – Galen Jul 15 '21 at 21:06
  • @Galen I've read the page. what exactly are you trying to show me? does this only remove one edge at a time and I have to just run it inside a loop? the examples in the documentation show multiple communities with the code on the bottom, but for me it isnt returning anything? – John Smith Jul 15 '21 at 21:10
  • Sorry, I should have expressed that I was putting the link there for passer-by-readers that are unfamiliar with what the algorithm is supposed to do. – Galen Jul 15 '21 at 21:11
  • @Galen oh my mistake. Thank you – John Smith Jul 15 '21 at 21:13
  • 1
    Can you show (or at least describe) the output of `tuple(sorted(c) for c in next(ret))`? The reason the output of the second block of code is empty appears to be because `ret` is "exhausted" - you looped through all of its values in creating the tuple, and now it's empty. – Joel Jul 18 '21 at 11:54

0 Answers0