from scipy.sparse import *
from scipy import *
from numpy import *
import csv
S = dok_matrix((10000,10000), dtype=bool)
f = open("your_file_name")
reader = csv.reader(f)
for line in reader:
S[int(line[0]),int(line[1])] = True
This contains a list (self.rows) of rows, each of which is a sorted list of column indices of non-zero elements. It also contains a list (self.data) of lists of these elements.
如果需要邻接矩阵,可以执行以下操作:
您可能还对Networkx感兴趣,这是一个纯python网络/绘图包。
从网站:
使用scipy的lil_matrix(列表矩阵列表)的示例。
代码:
输出:
相关问题 更多 >
编程相关推荐