Let’s say I have two arrays of shape (3,2,3)
a = np.array([[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]],[[13,14,15],[16,17,18]]])
b = np.array([[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]],[[13,14,15],[16,17,18]]])
a.shape
b.shape
I would like to join these two arrays by adding a new dimention to get (2,3,2,3) like this:
c = np.array([[[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]],[[13,14,15],[16,17,18]]], [[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]],[[13,14,15],[16,17,18]]]])
c.shape
How would I do this?
>Solution :
You can use numpy.stack (Join a sequence of arrays along a new axis.) on axis=0 base on concatenate and add a new dimension on the first dimension.
c = np.stack((a, b), axis=0)
print(c.shape)
# (2, 3, 2, 3)