2017-05-24 24 views
0

我在目录中有多个numpy数组(.npy)。我想连接所有这些。我曾尝试过:连接目录中的numpy数组

files = sorted(glob.glob(r'C:\Users\x\samples' + '/*.npy')) 
    for i in range(len(files)): 
       data= np.concatenate(files, axis=0) 

但它给出了一个错误:无法连接零维数组。 任何解决方案?

回答

0

np.concatenate适用于阵列。但是,files是字符串。您应该先读取文件以获取阵列:

files = sorted(glob.glob(r'C:\Users\x\samples' + '/*.npy')) 
arrays = [] 
for f in files: 
    arrays.append(np.load(f)) 
data = np.concatenate(arrays) 
+0

作品,谢谢! –