我正在用python做图形聚类。该算法要求图G传递的数据必须是邻接矩阵。但是,为了像这样将adjacency-matrix作为numpy-array:
import networkx as nx
matrix = nx.to_numpy_matrix(G)我得到一个内存错误。消息是MemoryError: Unable to allocate 2.70 TiB for an array with shape (609627, 609627) and data type float64
然而,我的设备是新的(联想E490),windows 64位,内存8 Gb
其他重要信息可能是:
Number of nodes: 609627
Number of edges: 915549整个故事是这样的:
Graphtype = nx.Graph()
G = nx.from_pandas_edgelist(df, 'source','target', edge_attr='weight', create_using=Graphtype)马尔可夫聚类
import markov_clustering as mc
import networkx as nx
matrix = nx.to_scipy_sparse_matrix(G) # build the matrix
result = mc.run_mcl(matrix) # run MCL with default parameters
MemoryError

发布于 2020-05-06 17:24:22
您尝试创建的矩阵的大小为float64的609627x609627。由于每个float64使用8字节的内存,您将需要609627*609627*8~3TB内存。您的系统只有8 8GB,即使增加了物理内存,3TB似乎也太大了,无法操作。假设您的节点it是整数,您可以使用dtype=unit4(以说明所有609627节点),但它仍然需要超过TB的内存,这听起来是无法访问的。你正在尝试做什么,似乎你有一个稀疏矩阵,你可能会有另一种可能的方法来实现你的目标。邻接矩阵(除非压缩)似乎很难实现。
也许你可以受益于这样的事情:
to_scipy_sparse_matrix(G, nodelist=None, dtype=None, weight='weight', format='csr')在networks包中。或者更确切地说,使用edgelist来计算您想要实现的目标。
https://stackoverflow.com/questions/61631553
复制相似问题