问题描述
我有一个如下所示的矩阵(scipy.sparse.csr.csr_matrix 类型):
(0,31) 0.000528868711772147
(0,32) 4.84173520932837e-05
(0,33) 4.10541590795596e-05
(0,34) 0.000408771225384504
(0,35) 0.000795847618707398
: :
(16086,118806) 0.00047416210140481
(16086,118809) 0.00856067420817794
(16086,118826) 0.00420368450693882
(16086,131832) 0.00111739160477843
(16086,131905) 0.00389774479846667
我正在尝试将它传递给一个 numpy 数组。我试过同时使用 .toarray()
和 .todense()
但它们似乎都不起作用,因为我收到以下错误:
Unable to allocate 18.0 GiB for an array with shape (16087,150360) and data type float64
你知道怎么做吗?提前致谢。
解决方法
你的内存不足以进行这样的操作,将数据分块并逐块进行此操作