我尝试将多个numpy文件合并成一个大文件,我试图按照这个链接 Python append multiple files in given order to one big file 的方法进行操作,以下是我的做法:
import matplotlib.pyplot as plt
import numpy as np
import os, sys
#Read in list of files. You might want to look into os.listdir()
path= "/home/user/Desktop/ALLMyTraces.npy/test"
#Test folder contains all my numpy file traces
traces= os.listdir(path)
# Create new File
f = open("/home/user/Desktop/ALLMyTraces.npy", "w")
for j,trace in enumerate(traces):
# Find the path of the file
filepath = os.path.join(path, trace)
# Load file
dataArray= np.load(filepath)
f.write(dataArray)
文件已创建,为了验证我是否拥有正确的内容,我使用了以下代码:
import numpy as np
dataArray= np.load(r'/home/user/Desktop/ALLMyTraces.npy')
print(dataArray)
这个错误是由以下原因产生的:
dataArray= np.load(r'/home/user/Desktop/ALLMyTraces.npy')
File "/usr/lib/python2.7/dist-packages/numpy/lib/npyio.py", line 401, in load
"Failed to interpret file %s as a pickle" % repr(file))
IOError: Failed to interpret file '/home/user/Desktop/ALLMyTraces.npy' as a pickle
我真的不知道问题出在哪里。非常感谢任何帮助。