I have two very similar programs whose functions differ only slightly. Within both programs, a 1568 x 1568 numpy matrix is produced. In one of my programs, this matrix creation works perfectly, however, in the other, I receive a MemoryError. Error message below:
a = empty(shape, dtype, order)
MemoryError
Also, when I copy the section of code that creates the matrix, from the program that does work, into its own python file, this too produces the MemoryError.
The code below reproduces the error:
import matplotlib.pyplot as plt
import numpy as np
Z = np.zeros((1568, 1568))
fig = plt.figure(figsize=(6,6))
X = np.arange(0, 1568, 0.1)
Y = np.arange(0, 1568, 0.1)
X, Y = np.meshgrid(X, Y)
plt.contourf(X, Y, Z)
plt.show()
I don't think this is caused by the fact that I'm using 32 bit python rather than 64 bit (as is the case with others who have posted questions with similar problems), purely because of the fact that this does work in my other program and the matrix should only be using 9.83 MB of RAM anyway.
Any help would be greatly appreciated.
X, Y = np.meshgrid(X, Y), as that is going to be two huge15680x15680matrices - Daniel Fmeshgrid,XandYare both roughly 1.8 GB in size, andcontourfwill also need to use some RAM. With 32 bit you are limited to 4 GB total RAM size so yes, it is related to you using 32 bit Python. - Nils Wernerlinspaceassignments the same? i.e. is the step size 0.1? I'm not sure that code would work as written asZis 1/10th the size ofXandY- Daniel Fplt.contourf(X, Y, Z)should fail becauseZ.shapeis(1568, 1568)andX.shape == Y.shape == (15680, 15680)and in the docs it states "X and Y must both be 2-D with the same shape as Z," - Daniel F