简体   繁体   中英

Module 'networkx' has no attribute 'blockmodel'?

I'm trying to use the networkx blockmodel function, but Python keeps saying there is no attribute 'blockmodel'. I am using the example code in the documentation in the link here .

I do have networkx installed, and many other functions are working. Only this one seems to complain. Help is much appreciated.

The blockmodel function has been replaced in the latest version of networkx (you are looking at older documentation) with quotient_graph .
Here is an example of generating a blockmodel

>>> G = nx.path_graph(6)
>>> partition = [{0, 1}, {2, 3}, {4, 5}]
>>> M = nx.quotient_graph(G, partition, relabel=True)
>>> list(M.edges())
[(0, 1), (1, 2)]

See https://networkx.github.io/documentation/stable/reference/algorithms/generated/networkx.algorithms.minors.quotient_graph.html?highlight=blockmodel for the updated documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM