- 沿着新轴上合并:stack(arrays, axis=0)
沿着轴0合并
In [3]: import numpy as np
...: a = np.array([[1,2,3],[4,5,6]])
...: b = np.array([[6,5,6],[7,8,9]])
...: np.stack((a,b),axis=0)
...:
Out[3]:
array([[[1, 2, 3],
[4, 5, 6]],
[[6, 5, 6],
[7, 8, 9]]])
In [4]: np.stack((a,b),axis=0).shape
Out[4]: (2, 2, 3)
沿着轴1合并
In [5]: np.stack((a,b),axis=1)
Out[5]:
array([[[1, 2, 3],
[6, 5, 6]],
[[4, 5, 6],
[7, 8, 9]]])
In [6]: np.stack((a,b),axis=1).shape
Out[6]: (2, 2, 3)
沿着轴2合并
In [7]: np.stack((a,b),axis=2)
Out[7]:
array([[[1, 6],
[2, 5],
[3, 6]],
[[4, 7],
[5, 8],
[6, 9]]])
In [8]: np.stack((a,b),axis=2).shape
Out[8]: (2, 3, 2)
- 水平合并:vst