Reputation: 137
There is a function in networkX called k_clique_communities that find k-clique communities in graph, and I run the code on my data.
K5 = nx.convert_node_labels_to_integers(G,first_label=2)
G.add_edges_from(K5.edges())
c = list(nx.k_clique_communities(G, 4))
list(c[9])
[145, 276, 277, 278, 279, 138]
list(c[10])
[353, 146, 244, 198, 327, 252]
I am confused about the result here.
What does list(c[9]) mean?
What's the difference between list(c[9]) and list(c[10])?
Upvotes: 2
Views: 3302
Reputation: 8801
The documentation for k_clique_communties says that
A k-clique community is the union of all cliques of size k that can be reached through adjacent (sharing k-1 nodes) k-cliques.
Now each individual list item will a collection of (union of) k-sized cliques thatw each other and shared (k-1) nodes. In your case c[9]
returns
[145, 276, 277, 278, 279, 138]
So this is a union of 4-sized cliques that were adjacent to other and share 3 nodes with each other. You can visualize these only these nodes from your graph and then you will see that these were adjacent cliques sharing 3 nodes with each other.
Now to the next part, c[0]
and c[1]
are nothing but individual list of such union of k-cliques with the properties described above, i.e. it might be the case that there must have multiple union of 4 sized cliques which share 3 nodes in your graph, so you can access the first union at c[0]
, next at c[1]
and so on
Upvotes: 2
Reputation: 1916
list(c[0])
means that c
is a list, you are taking the object at index 0, and attempting to initialize a new list
with its contents. The difference between c[0]
and c[10]
is that they are different elements in the list c
. If you are confused about types, a helpful tip is to throw in a print(type(x))
statement. print(type(c))
, in this case, would give you <type 'list'>
. Here is the doc page on lists for more help getting started.
Upvotes: -1