Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 找到共同邻居的数目_Python_Networking_Graph_Social_Sna - Fatal编程技术网

Python 找到共同邻居的数目

Python 找到共同邻居的数目,python,networking,graph,social,sna,Python,Networking,Graph,Social,Sna,您好,您能帮我找到网络中常见邻居的数量吗 这是我的代码,但我不知道如何继续 ` import networkx as nx import pandas as pd import numpy as np import matplotlib.pyplot as plt G=pd.read_csv('karate.txt',header=None,delim_whitespace=True,names=['n1','n2']) G2=nx.from_pandas_edgelist(G,sourc

您好,您能帮我找到网络中常见邻居的数量吗 这是我的代码,但我不知道如何继续

`

import networkx as nx
import pandas as pd
import numpy as np
import matplotlib.pyplot  as plt

G=pd.read_csv('karate.txt',header=None,delim_whitespace=True,names=['n1','n2'])
G2=nx.from_pandas_edgelist(G,source='n2',target='n1')
#print(G2.edges())
#print(G2.degree())
e=[]


for n in G2:
    for c in G2:
        if n!=c:  
         G5=sorted(nx.common_neighbors(G2,n,c))
        
         edges.append([n,c,len(G5)])
        
    print(edges)`

这里是一个单行程序,它将计算节点1和节点2之间的公共邻居

import networkx as nx

G = nx.karate_club_graph()

common_nbor = len(set([n for n in G.neighbors(1)]).intersection(set([n for n in G.neighbors(2)])))
common_nbor=4

请重复和[如何提问]()。“演示如何实现此功能”不是堆栈溢出问题。