Questions tagged «preserve»

6
在磁盘上保留numpy数组的最佳方法
我正在寻找一种保留大型numpy数组的快速方法。我想将它们以二进制格式保存到磁盘中,然后相对快速地将它们读回到内存中。不幸的是,cPickle不够快。 我找到了numpy.savez和numpy.load。但是奇怪的是,numpy.load将一个npy文件加载到“内存映射”中。这意味着对数组的常规操作确实很慢。例如,像这样的事情真的很慢: #!/usr/bin/python import numpy as np; import time; from tempfile import TemporaryFile n = 10000000; a = np.arange(n) b = np.arange(n) * 10 c = np.arange(n) * -0.5 file = TemporaryFile() np.savez(file,a = a, b = b, c = c); file.seek(0) t = time.time() z = np.load(file) print "loading …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.