有大数组,我想阅读并堆叠起来,如:内存有效的方式堆叠阵列中的蟒蛇
>>> 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])
什么是读取和附加阵列最多的内存有效的方法?
多少个数组和多少个大小? – hpaulj
'y = npy.arange(20).reshape(5,2)'从您的示例中产生错误。 – saintsfan342000
像这样使用'npy.append'并不理想,速度快,但不应该影响空间的使用。迟早,当您添加更多文件时,您将遇到内存错误。在某些时候,得到的数组将比RAM更大。还有其他最近关于串联数组的问题。 – hpaulj