如何在 python 中合并大小为 128x128 的数组或图像
How to combine arrays or images of size 128x128 in python
我有 'n' 128x128 的灰度 images/arrays,我想加入它们以获得大小为 128x128xn 的数组。
我尝试了几种方法,但我可以得到 nx128x128。
例如
a1 = np.random.rand(128,128)
a2 = np.random.rand(128,128)
b1 = np.random.rand(128,128)
b2 = np.random.rand(128,128)
c1 = np.random.rand(128,128)
c2 =np.random.rand(128,128)
X1 = [a1, a2]
X2 = [b1, b2]
X3 = [c1, c2]
X = [X1, X2, X3]
X = np.array(X)
X.shape
我的最终形状为 (3, 2, 128, 128)
但我对 3x128x128x2 感兴趣
请帮助我怎样才能得到这个。
我想你想要np.moveaxis将第二个轴移动到最后一个:
interesting = np.moveaxis(X, 1, -1)
我有 'n' 128x128 的灰度 images/arrays,我想加入它们以获得大小为 128x128xn 的数组。 我尝试了几种方法,但我可以得到 nx128x128。 例如
a1 = np.random.rand(128,128)
a2 = np.random.rand(128,128)
b1 = np.random.rand(128,128)
b2 = np.random.rand(128,128)
c1 = np.random.rand(128,128)
c2 =np.random.rand(128,128)
X1 = [a1, a2]
X2 = [b1, b2]
X3 = [c1, c2]
X = [X1, X2, X3]
X = np.array(X)
X.shape
我的最终形状为 (3, 2, 128, 128)
但我对 3x128x128x2 感兴趣
请帮助我怎样才能得到这个。
我想你想要np.moveaxis将第二个轴移动到最后一个:
interesting = np.moveaxis(X, 1, -1)