numpy 矩阵的最大元素/大小?
numpy 矩阵的最大元素/情况是什么,或者 numpy 矩阵的最大大小是多少?
上面的代码返回可变矩阵大小的内存错误...那么它取决于什么环境因素(可用的连续内存量的数量?)?
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'))
问题:什么时候以及为什么返回“内存错误”?
PS:我使用Windows上可用的最后一个Python和numpy(是的我知道......)7 64位。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅内存上限?。
至于何时返回内存错误,答案是为其中一个大对象分配内存时。它可以是任何一个,因为当您分配
res
的后面几行时,您将拥有比以前更高的内存量,因为 numpy 矩阵直到之后才会被垃圾收集您已将r
、s
或t
指向另一个对象(在下一次迭代中创建的新矩阵)。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 pointedr
,s
, ort
at another object (the new matrix created on the next iteration).