. Advertisement .
..3..
. Advertisement .
..4..
This is a blog for developers who have worked with numpy arrays before. If you have spent any time working with large numpy arrays, then you might have seen the following error “numpy.core._exceptions.MemoryError: Unable to allocate array with shape”. This post will show you some techniques you can use to solve this problem.
When dose The Error “numpy.core._exceptions.MemoryError: Unable to allocate array with shape” occur
When attempting to use numpy and the following command that you used
nmp.zeros((789412, 78, 98754), dtype='uint8')
But you’re facing following error.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
numpy.core._exceptions.MemoryError: Unable to allocate array with shape (789412, 78, 98754) and data type uint8
How To Fix The Error “numpy.core._exceptions.MemoryError: Unable to allocate array with shape”?
Option 1: Increase pagefile
Simply increase pagefile in Windows 10. Follow the steps below:
- To begin with, press the Windows key.
- Then, type SystemPropertiesAdvanced in the search box.
- Next, select Run as administrator from the drop-down menu.
- Select Settings from the Performance menu.
- After that, go to the Advanced tab. Now, choose Change…
- Uncheck Managing the size of paging files across all drives automatically.
- Then, choose Custom size and enter the appropriate dimensions.
- To exit the Virtual Memory, Performance Options, as well as System Properties Dialog, press Set, and OK.
- Restart your computer.
- Your problem should now be resolved.
Option 2: Increase pagefile in Windows 8
- Press the WindowsKey + X -> select System in the popup menu
- Tap or click Advanced system settings. You might be asked for an admin password or to confirm your choice
- On the Advanced tab, under Performance, tap or select Settings.
- Tap or select the Advanced tab, under Virtual memory-> tap or select Change
- Clear the Automatically manage paging file size for all drives check box.
- Under Drive [Volume Label], tap or select the drive that contains the paging file
- Select Custom size, enter a new size in megabytes in the initial size (MB) or Maximum size (MB) box, tap or select Set -> tap or click OK
- Reboot your system
Option 3: Switch dtype to uint8
Simply switch dtype to uint8. from
mask = nmp.zeros(edges.shape)
to this
mask = nmp.zeros(edges.shape,dtype='uint8')
Option 4: Change the data type to numpy.uint8
data['label'] = data['label'].astype(np.uint8)
Option 5: Switch from a 32-bit to a 64-bit version
In Python, you need switch from a 32-bit to a 64-bit version. Indeed, a 32-bit software, like a 32-bit CPU, can adress a maximum of 4 GB of RAM.
With a 64-bit version of Python (the one labeled x86-64 in the download page), the problem is solved.
Make sure the version that is existing by entering the interpreter. With a 64-bit version, have:
Python 3.7.5rc1 (tags/v3.7.5rc1:4082f600a5, Oct 1 2019, 20:28:14) [MSC v.1916 64 bit (AMD64)]
that [MSC v.1916 64 bit (AMD64)] means “64-bit Python”.
Conclusion
We hope you found our blog post on solving the error “numpy.core._exceptions.MemoryError: Unable to allocate array with shape”. If you have any further queries or concerns about this topic, please leave a comment. Thank you for reading; we are always glad when one of our articles provides useful knowledge on this subject!
Leave a comment