igraph.graph.community_walktrap does not work properly for the ndarray formed graph

We are using ig.Graph.Adjacency((simlarity_matrix_np>0).tolist(), mode='undirected') to generate the graph, and using clusters = ig.Graph.community_walktrap(similarity_matrix, weights='sim', steps=4).as_clustering() to run the walktrap algorithm, but we got an error. Number of steps is greater than number of rows in merges matrix: found 499 steps, 0 rows. – Invalid value. Could someone help us to solve this problem? Thank you!

What version of python-igraph were you using? Make sure you are using the latest, currently 0.10.4.

Whenever you encounter a problem like this, it is good practice to verify if it is still present in the latest version. I seem to recall fixing a similar issue a long time ago. If the problem is still present, please show us a complete minimal example that reproduces it.

Thank you for your reply. Now I have to use the lower version of igraph to do my work because the environment is restricted to python 3.6. But I figure out a way to overcome that, just set the weight of each edge not to zero, that will be fine.

If this restriction is present on a system you don’t have administrator access to, I suggest you ask your sysadmin to install a newer Python. Version 3.6 reached end of life in 2021 December.

The policy we use for python-igraph is that each new version supports Python versions that are at that time officially supported by the Python Software Foundation.

Walktrap interprets edge weights are (unnormalized) probabilities, thus a zero weight is theoretically equivalent to a non-existent edge. Thus zero-weight edges are best removed.

The error you saw is likely due one of two bugs in old versions where walktrap wouldn’t work correctly with disconnected graphs:

These are both corrected in the latest version, which I strongly suggest you upgrade to.