Networkx二部图:具有相同编号的不同集合的节点 [英] Networkx bipartite graphs: nodes of different sets with the same number

查看:298
本文介绍了Networkx二部图:具有相同编号的不同集合的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在用Networkx构造二部图时遇到了一个主要问题.

I encountered a major problem while constructing a bipartite graph with Networkx.

我说2列csv中的节点

I take the nodes from a 2-columns csv, say

CODINV2;APPLN_ID

1;3
1;4
1;5
2;3
2;6
3;6
4;12

将每列移动到单独的列表中后,存储节点的代码为

After moving each column into a separate list the code to store the nodes is

G=nx.Graph()
G.add_nodes_from(codinv, bipartite=0)
G.add_nodes_from(app_id, bipartite=1)

然后我添加边缘(基于csv行):

Then i add the edges (based on the csv rows):

for index,row in appl.iterrows():
    G.add_edge(row['APPLN_ID'], row['CODINV2'])

现在实际上已经创建了链接,但是如果我再次查看节点属性,那么现在很多错误地将它们视为

Now the links are actually created, but if i look again at nodes attributes, now many of them are wrongly considered as

bipartite=1

基本上,如果属于不同集合的两个节点具有相同的数目,则似乎会引起很多混乱,尤其是在假设的一种模式投影方面.

Basically if two nodes belonging to different sets have the same number a lot of confusion seems to arise, especially in terms of an hypothetical one mode projection.

推荐答案

其原因是该图按其名称存储该节点.

The reason for this is that the graph stores the node by its name.

如果它通过名称3输入一个节点并认为bipartite=1,则说出话然后再添加3,它将解释为同一节点.如果这次您告诉它bipartite=0,它将覆盖旧条目.因此,现在节点3具有bipartite=0.

If it enters one node by name 3 and thinks bipartite=1, say and then later adds 3 again, it interprets that as the same node. If this time you tell it bipartite=0, it will overwrite the old entry. So now, node 3 has bipartite=0.

如果要存储两个不同的节点3,则它们将必须具有不同的名称.您可以尝试将其作为字符串:'3a''3b'.或其他任何名称,但33将不起作用.

If you want to store two different node 3's, then they will have to have different names. You could try doing it as strings: '3a' and '3b'. Or any other names, but 3 and 3 will not work.

这篇关于Networkx二部图:具有相同编号的不同集合的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆