Reputation: 443
I have multiple numpy arrays (.npy) in a directory. I want to concatenate all of them. I have tried:
files = sorted(glob.glob(r'C:\Users\x\samples' + '/*.npy'))
for i in range(len(files)):
data= np.concatenate(files, axis=0)
but it gives an error: zero-dimensional arrays cannot be concatenated. any solution?
Upvotes: 0
Views: 1269
Reputation: 794
np.concatenate
works on arrays. However, files
are strings. You should first read the files to obtain arrays:
files = sorted(glob.glob(r'C:\Users\x\samples' + '/*.npy'))
arrays = []
for f in files:
arrays.append(np.load(f))
data = np.concatenate(arrays)
Upvotes: 1