import csv
import collections
import itertools
fp = open('direct.csv')
# counts how many times each pair worked together
pairs = {}
# each element of `project` is a person
for project in (p[:-1].split(',') for p in fp):
project.sort()
# someone is alone here
if len(project) == 1:
continue
# iterate over each pair
for i in range(len(project)):
for j in range(i+1, len(project)):
pair = (project[i], project[j])
# increase `pairs` counter
pairs[pair] = pairs.get(pair, 0) + 1
from pprint import pprint
pprint(pairs)
" direct.csv"我从CAIDA网络拓扑(2x4000)矩阵文件获得的矩阵文件如下所示: 10010 2516; 10010 37907; 10010 55385; 10010 55387; 10010 58650; 10010 7690; 10010 9351; 10010 9615; 10010 9622; 10010 9990; 10012 23720; 10013 4686; 10015 10002; 10015 17945; 10015 18264; 10015 2512; 10015 9351; 10015 9997; 我必须制作一个邻接矩阵,但是当我必须这样做时,我最终得到一个2GB的文件而我无法做任何事情所以我使用这个代码所以python可以处理所有数据并做一些事情用它(从邻接矩阵中取出所有的零)
我的问题是,是否可以知道一个AS有多少连接。例如10010 = 7; 10015 = 5,具有最高 - 最低阶