MemoryError in python

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ttbluemoon0220
    New Member
    • May 2010
    • 1

    MemoryError in python

    When I tried to calculate two-dimensional FFT of the array with 4096*4096 elements by using 64bit Windows XP with 64GB,
    I ran into the Memoryerror althogh the usage of memory was less than 1GB.

    I am wondering whether python has the upper limit memory usage.
    Even if so, I don't know how to set the upper limit memory usage.

    I showed you my code as follows.

    Could you help me, please ?

    -------------------------------------------------------
    Code:
     
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    if __name__ == '__main__':
        pass
    
    import scipy 
    import scipy.io
    import scipy.fftpack
    import scipy.stats
    import pylab 
    import random
    import os
    import math
    import cmath
    
    h=   2.46342852e-03  # rms of height
    size_mesh = 1.0 
    l=   85.16152053/math.sqrt(2.0)*80.0/512/size_mesh 
    N=    512
    L=    512 
    
    F = scipy.zeros((N,N),dtype=scipy.complex128 )
    
    
    for I in scipy.arange(0,N-1,1):
        for J in scipy.arange(0,N-1,1):
            Kx=2.0*math.pi*I/L
            Ky=2.0*math.pi*J/L
            if (I == 0) or (I == N/2) or (J == 0) or (J == N/2):
                rdm_number= random.gauss(0,1)
            else:
                rdm_number= (random.gauss(0,1) +1.0j*random.gauss(0,1) )/math.sqrt(2.0)
            F[I,J]=2.0*math.pi*L*math.sqrt(l**2*h**2/(4.0*math.pi)*scipy.exp(-Kx**2*l**2/4.0 -Ky**2*l**2/4.0))*rdm_number
            
    for I in scipy.arange(1,N/2-1,1):
        for J in scipy.arange(1,N/2-1,1):
            F[N-I,N-J]= F[I,J].conjugate()
        
    for I in scipy.arange(N/2+1,N-1,1):
        for J in scipy.arange(1,N/2-1,1):
            F[N-I,N-J]= F[I,J].conjugate()
     
    RS = scipy.fftpack.ifft2(F)
    
    del F
    
    scipy.io.write_array(
        os.path.join("RS.txt"), 
            RS, 
            separator=" " 
        )
    
    pylab.clf()
    Z = scipy.real(RS) 
    
    del RS
    
    pylab.imshow(Z)
    pylab.contour(Z)
    pylab.xlabel('x')
    pylab.ylabel('y')
    pylab.savefig( os.path.join("RS.png"))
    pylab.clf()
    
    del  Z
    --------------------------------------------------
Working...