Concatenate 3-d arrays python

Viewed 11642

I want to concatenate empty 3d numpy array

   #2d array works 
   xs = np.array([[1,2,3,4,5],[10,20,30,40,50]])
   ys = np.array([]).reshape(0,5)
   zs = np.vstack([ys, xs])

   #3D does not work
   bb = np.array([]).reshape(1080, 1920, 0) # empty 

   ss = np.random.rand(1080, 1920,2) #

   dd = np.vstack([bb, ss]) # generate an error

It is possible to do that ?

1 Answers

Use concatenate along the last axis to mimic the behavior you're seeing with 2D arrays:

np.concatenate([bb, ss], -1)

>>> np.concatenate([bb, ss], -1).shape
(1080, 1920, 2)
Related