這就是你如何使用pytables來完成的。雖然我希望你耐心,有很大的空間。
import tables as tb
import numpy as np
import time
f = tb.openFile('humongusFile.h5', 'w')
n = 100000
x = f.createCArray(f.root, 'x', tb.Float16Atom(), (n,n), filters=tb.Filters(5, 'blosc'))
t0 = time.time()
for i in range(n):
x[i] = np.random.random_sample(n)* 10
x.flush() # dump data to disk
t1 = time.time()
print t1 - t0
print "Done creating test data"
y1 = f.createCArray(f.root, 'y1', tb.Float16Atom(), (n,n), filters=tb.Filters(5, 'blosc'))
y2 = f.createCArray(f.root, 'y2', tb.Float16Atom(), (n,n), filters=tb.Filters(5, 'blosc'))
t2 = time.time()
print t2 - t1
print "Done creating output array"
expr = tb.Expr("where((x >= 5.23) & (x < 8.55), x, 0)")
expr.setOutput(y1)
expr2 = tb.Expr("where((x >= 5.23) & (x < 8.55), x, 0)")
expr2.setOutput(y2)
t3 = time.time()
print t3 - t2
print "Starting evaluating first output"
expr.eval()
print "Starting evaluating second output"
expr2.eval()
print "Done"
t4 = time.time()
print t4 - t3
爲什麼問題是內存時的標題速度? – cyborg
1e6 x 1e6物品的數組有1億(1e12)個物品。即使你存儲了一個單一的位,你需要125GB **來存儲你的'raster_data'數組**,單精度浮點數需要4TB的內存...... – Jaime
答案取決於你要去的是什麼處理類,類中有多少元素(稀疏矩陣?),以及如何存儲數據。 – cyborg