Keep getting MemoryError while calling copy.deepcopy()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lawbaal
    New Member
    • Dec 2010
    • 2

    Keep getting MemoryError while calling copy.deepcopy()

    As the title tells, the detail is: There is a dictionary to be deepcopied. it has 100 key-value pairs. every value is a list of 200000 float numbers. I'm perform deepcopy to everyone of the value like below:
    Code:
     curr_di_in_a = {}
     for key,v in to_be_copy.items():
         curr_di_in_a[key] = copy.deepcopy(v)
    This process will be in a loop of 3 times. And an MemoryError occurs after 2 times looped.
    It seems there is not enough space for the action. But the memory of the machine is about 4G. So is there any way to make a full use of the physical memory, or maybe I have made some mistakes? Help me! Thanks.
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    I only see one loop. Where are the other two?

    If the values are lists of numbers, why not do this:
    Code:
     curr_di_in_a = {}
     for key,v in to_be_copy.items():
         curr_di_in_a[key] = v[:]

    Comment

    Working...