简体   繁体   English

Numpy:创建一个空数组导致内存错误?

[英]Numpy: creating an empty array results in memory error?

I need to store a ton of information in a numpy array. 我需要在numpy数组中存储大量信息。 It needs to be of the following shape: 它需要具有以下形状:

facefeature1s = np.empty([2000,64,64,64,32])

When I run this, i get a memory error. 当我运行它时,我得到一个内存错误。 What can I do about this? 我该怎么办?

Error is: 错误是:

    MemoryError                               Traceback (most recent call last)
<ipython-input-271-2c56a37b4a7c> in <module>()
----> 1 facefeature1s = np.empty([2000,64,64,64,32])

As @Jaime says in the comments, your array is too big. 正如@Jaime在评论中所说,你的阵列太大了。 IF you really need such a huge array, you can use numpy.memmap() to work on the array using the hard drive: 如果你真的需要这么大的数组,你可以使用numpy.memmap()来使用硬盘驱动器处理数组:

a = np.memmap('filename.myarray', dtype=np.float64, mode='w+',
              shape=(2000, 64, 64, 64, 32))

The next time you open the array, use mode='r' , or mode='r+' . 下次打开数组时,请使用mode='r'mode='r+'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM