import numpy as np import scipy.sparse as sparse from sklearn import preprocessing
row = list() col = list() index = dict() i = 0 withopen('net.txt') as file: for line in file: pA = line[0:8] pB = line[13:21] if pA notin index: index[pA] = i i = i + 1 if pB notin index: index[pB] = i i = i + 1 row.append(index[pA]) col.append(index[pB]) row = np.array(row) col = np.array(col) Mat = sparse.coo_matrix((np.ones(len(row)),(row,col)),shape=(i,i)).tocsr() Mat=preprocessing.normalize(Mat, norm='l1').T