Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我们有一个 3d 数组A.shape = (100, 5, 5),每个小矩阵(5,5)都是一个图像,现在我想将这个 3d 数组重塑为图像的方形网格B.shape=(50,50),使图像布局为 10*10 网格。
A.shape = (100, 5, 5)
(5,5)
B.shape=(50,50)
我可以使用np.stack某种工具来做到这一点,但我想知道是否可以使用np.einsum?
np.stack
np.einsum
哦,我想我刚刚想通了
A = np.einsum('ijk->jik', A.reshape(10,50,5)).reshape(50,50); pl.imshow(A); pl.show()
有两个简单的解决方案。你的和它的“转置”:
例子:
>>> ABCD.shape (4, 41, 27) >>> AC_BD = np.einsum('jik', ABCD.reshape(2, 82, 27)).reshape(82, 54) >>> AB_CD = np.einsum('ikjl', ABCD.reshape(2, 2, 41, 27)).reshape(82, 54) >>> Image.fromarray(AC_BD).show() >>> Image.fromarray(AB_CD).show()