连接3维数组python

时间:2018-10-24 21:02:42

标签: python arrays numpy concatenation

我想连接空的3d numpy数组

   #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

有可能这样做吗?

1 个答案:

答案 0 :(得分:1)

沿最后一个轴使用concatenate来模仿您在2D数组中看到的行为:

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

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