Skip to content Skip to sidebar Skip to footer

Merging Multiple Numpy Arrays

i have 3 numpy arrays which store image data of shape (4,100,100). arr1= np.load(r'C:\Users\x\Desktop\py\output\a1.npy') arr2= np.load(r'C:\Users\x\Desktop\py\output\a2.npy') arr3=

Solution 1:

This will do the trick:

merge_arr = np.concatenate([arr1, arr2, arr3], axis=0)

np.stack arranges arrays along a new dimension. Their dimensions (except for the first) need to match.

Demo:

arr1 = np.empty((60, 4, 10, 10))
arr2 = np.empty((14, 4, 10, 10))
arr3 = np.empty((6, 4, 10, 10))
merge_arr = np.concatenate([arr1, arr2, arr3], axis=0)
print(merge_arr.shape)  # (80, 4, 10, 10)

Post a Comment for "Merging Multiple Numpy Arrays"