np.stack文档解释:
Join a sequence of arrays along a new axis.
The
axis
parameter specifies the index of the new axis in the dimensions of the result. For example, ifaxis=0
it will be the first dimension and ifaxis=-1
it will be the last dimension.
产生一个给定axis的新轴 ,沿着该轴堆砌数组
下面是代码测试:
a = np.arange(8).reshape((2,2,2))
array([[[0, 1],
[2, 3]],
[[4, 5],
[6, 7]]])
b = np.arange(8).reshape((2,2,2))+1
array([[[1, 2],
[3, 4]],
[[5, 6],
[7, 8]]])
第一个2是2个样本,后面2*2是像素矩阵,要将a,b变成2*2*2*2,第4个2表示颜色通道:
c = np.stack((a,b),axis=3)
array([[[[0, 1],
[1, 2]],
[[2, 3],
[3, 4]]],
[[[4, 5],
[5, 6]],
[[6, 7],