2
我想存储一个数组,以在头文件中添加一些额外的信息。我想使用numpy二进制'.npy'格式。我可以通过首先寻找数组部分的开头来读取带有额外标头的.npy文件的数组吗?我可以通过使用seek向numpy的.npy文件添加额外的头信息吗?
我想做这样的事情。如果一个标头是'n'字节:
from tempfile import TemporaryFile
outfile = TemporaryFile()
# Write header to first 'n' bytes.
...
# Write the array after the header.
outfile.seek(n)
x = np.arange(10)
np.save(outfile, x)
# Then to read it back in:
outfile.seek(0)
# Read the header.
...
# Read the array.
outfile.seek(n)
y = np.load(outfile)