我正在尝试创建一个非常大的 numpy 零数组,然后将值从另一个数组复制到这个大的零数组中。我正在使用 Pycharm 并且我不断收到:MemoryError
即使我尝试只创建数组。以下是我尝试创建零数组的方法:
import numpy as np
last_array = np.zeros((211148,211148))
我已尝试根据以下问题将 Pycharm 中的内存堆从 750m 增加到 1024m:https://superuser.com/questions/919204/how-can-i-increase-the-memory-heap-in-pycharm ,但这似乎没有帮助。
如果您想进一步说明,请告诉我。谢谢!
研究在 scipy 中使用稀疏数组功能:
scipy.sparse documentation .
这里有一组关于 scipy.sparse 库的示例和教程:
Scipy lecture notes: Sparse Matrices in SciPy
这可能会帮助您解决内存问题,并使一切运行得更快。
要创建一个空的稀疏数组,并按照您在评论中的要求在某些位置设置值:
Is there any way to create an empty array with values in certain positions, such as: last_array[211147][9] but everywhere else would be empty?
from scipy.sparse import *
values = [42]
row_ind = [211147]
col_ind = [9]
last_array = csc_matrix((values, (row_ind, col_ind)), shape=(211148,211148))
print(last_array[211147,9])