Skip to main content
 首页 » 编程设计

python之configuration_model() 在 Networkx 1.10 中获得关键字参数 'create_using' 的多个值

2024年10月24日12xxx_UU

我正在使用 networkx 1.9 和 python 2.7,并决定更新到最新的 1.10 版本。 在使用二分图生成器函数 configuration_model 时,我发现我之前使用的是:

import networkx as nx 
from networkx.algorithms import bipartite 
import networkx.algorithms.bipartite as bipartite 
aseq=[1 2 1] 
bseq=[2 1 1] 
G =bipartite_configuration_model(aseq,bseq, create_using=None, seed=None) 

新版本:

G =configuration_model(aseq, bseq, create_using=None, seed=None) 
 
configuration_model() got multiple values for keyword argument 'create_using' 

不再工作了。知道 create_using= 应该是什么吗?我阅读了源文件,但看不到需要什么!

请您参考如下方法:

我不确定版本之间的区别,但是对旧版本的小改动解决了这个问题。我对您的代码所做的更改是:

the definition of aseq and bseq as they gave error:

aseq=[1, 2, 1] # with commas between degree sequences 
bseq=[2, 1, 1] 

Calling the configuration_model function

G = bipartite.configuration_model(aseq,bseq, create_using=None, seed=None) # you had an underscore instead of a '.' 

然后用一个简单的color_map来区分属于每个部分的节点如下:

color_map = [] 
for n in G.nodes(): 
    if G.node[n]['bipartite'] == 0: 
        color_map.append('blue') 
    else: color_map.append('green') 

绘制产生的图形:

关于create_using参数,可以查看documentation .它说您可以使用它来确定返回图形的类型。默认情况下,它是一个具有平行边的多图。