首页 > 解决方案 > Python将数组附加到打开的文件

问题描述

我试图在计算过程中将 512x512 数组附加到文件中。数据太大而无法将它们存储在内存中,因此我想将数组附加到文件中。有多个文件必须扩展。这是我在一个小例子中的方法:

import numpy as np 
array1 = np.random.rand(512,512)
array2 = np.random.rand(512,512)
arrayList = [array1,array2]

for number,i in enumerate(arrayList):
    with open('path', 'ab') as f:
        np.save(f, arrayList[number])
arrayTest = np.load('path')

文件越来越大,所以我认为数组是附加的,但如果我加载它们,里面只有一个数组。我认为数组没有以正确的方式堆叠,并且 np load 只是在加载第一个数组时识别它。

标签: pythonarraysnumpy

解决方案


推荐阅读