有大型数组,我想读取它们并堆叠它们,如:
>>> x=npy.arange(10).reshape(5,2)
>>> y=npy.arange(10,20).reshape(5,2)
>>> npy.append(x,y)
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19])
>>> z.reshape(2,x.shape[0],x.shape[1])
array([[[ 0, 1],
[ 2, 3],
[ 4, 5],
[ 6, 7],
[ 8, 9]],
[[10, 11],
[12, 13],
[14, 15],
[16, 17],
[18, 19]]])
但结果会越来越大,最后程序会以out_of_memory停止。 代码是:
for i in range(1, days+1):
with rasterio.open(directory+"B04_"+str(i)+".jp2") as dataset:
band_4=dataset.read()[0]
with rasterio.open(directory+"B08_"+str(i)+".jp2") as dataset:
band_8=dataset.read()[0]
_=(band_8- band_4) / (band_8+ band_4+0.0000001)
ndvi=npy.append(ndvi, ـ )
ndvi=ndvi.reshape(days ,band_8.shape[0],band_8.shape[1])
读取和追加数组的内存效率最高的方法是什么?