0

what is the max element/case of a numpy matrix or what is the maximal size of a numpy matrix?

the code above returns memory error at variable matrix size...so from what environmental thing does it depend (number of sequential amount of memory available?)?

for ret in xrange(5000,7000,50):

   res = []
   for x in xrange(ret):
       temp=[]
       for y in xrange(ret):
           temp.append(random.random())
       res.append(temp)

  print "r"
  r = numpy.mat(res)
  print "s"
  s = numpy.mat(res,dtype='f4')
  print "t"
  w = numpy.mat(res,dtype('f8'))

question: when and why did it return "memory error"?

ps: i use last python and numpy available on windows (yes I know...) 7 64bit.

agf
  • 171,228
  • 44
  • 289
  • 238
sol
  • 1,389
  • 3
  • 19
  • 32
  • `res` is overridden in each loop. I think this was not your intention? Your last line is wrong, it should be `w = numpy.mat(res,dtype='f8')`. If `ret` is not overridden in your original code it is possible that you get a MemoryError because the resulting list is to big. – schlamar Jul 20 '11 at 08:33
  • Your inner two loops can be replaced by `r = np.random.random((ret, ret))` – Joe Kington Jul 21 '11 at 20:42
  • Also, your memory error is probably coming from the lists you're building, not numpy. Making a numpy array using nested lists will use much, much more memory than just making it directly. 7000x7000 is not very big at all. – Joe Kington Jul 21 '11 at 20:48

1 Answers1

1

See Upper memory limit?.

As for when it returned a memory error, the answer is when allocating memory for one of the large objects. It could be any one, because you'll be at a higher amount of memory than ever before by the time you allocate the later rows of res, since the numpy matrixes don't get garbage collected until after you've pointed r, s, or t at another object (the new matrix created on the next iteration).

Community
  • 1
  • 1
agf
  • 171,228
  • 44
  • 289
  • 238