The difference between np.stack and np.concatenate in numpy
Description: imgs is a list type. It stores a numpy array, shape = (1,h,w)
1.1, np.stack: stacking
Function: Add a new dimension before the first dimension, that is, CHW --> BCHW
- Case 1: imgs size is 1
im = np.stack(imgs) # (1,h,w) --> (1,1,h,w)
- Case 2: imgs size is 10
im = np.stack(imgs) # (1,h,w) --> (10,1,h,w)
1.2, np.concatenate: stitching
Function: On the basis of the original dimension, multiple numpy in imgs are dimensionally spliced.
- Case 1: imgs size is 1, axis=0
# axis=0表示在第一个维度上进行拼接操作
im = np.concatenate(imgs,axis=0)
im.shape = (1,h,w)
- Case 2: imgs size is 10, axis=0
# axis=0表示在第一个维度上进行拼接操作
im = np.concatenate(imgs,axis=0)
im.shape = (10,h,w)
- Case 3 : imgs size is 10, axis=1
# axis=1表示在第二个维度上进行拼接操作
im = np.concatenate(imgs,axis=1)
im.shape = (1,h*10,w)