csv to sparse matrix in python

后端 未结 3 976
长发绾君心
长发绾君心 2020-12-09 05:53

I have a big csv file which lists connections between nodes in a graph. example:

0001,95784
0001,98743
0002,00082
0002,00091

So this means that

3条回答
  •  借酒劲吻你
    2020-12-09 06:35

    If you want an adjacency matrix, you can do something like:

    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
    

提交回复
热议问题