Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numpy: creating an empty array results in memory error?

I need to store a ton of information in a numpy array. 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])
like image 379
wolfsatthedoor Avatar asked Jul 29 '26 12:07

wolfsatthedoor


1 Answers

As @Jaime says in the comments, your array is too big. IF you really need such a huge array, you can use numpy.memmap() to work on the array using the hard drive:

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+'.

like image 50
Saullo G. P. Castro Avatar answered Aug 01 '26 00:08

Saullo G. P. Castro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!