# H = patch height
# W = patch width
# X = grid height (i.e. number of patches to put along the first axis)
# Y = grid width (i.e. number of patches to put along the second axis)
X, Y, H, W = 3, 2, 3, 3
out = (
arr # (X Y) H W
.reshape(X, Y, H, W) # X Y H W
.swapaxes(1, 2) # X H Y W
.reshape(X * H, Y * W) # (X H) (Y W)
)
# Note that reshaping can only ever "regroup" axes,
# and that transposing can only ever reorder "groups" of axes.
2条答案
按热度按时间qzwqbdag1#
TLDR,用途:
你需要一个整形和移调的组合。考虑下面的小例子:
它看起来像:
假设我们想把补丁排列并连接成一个3 x 2的补丁图像,我们可以这样做:
输出:
说明:
h7wcgrx32#
使用
numpy.block
,您可以通过将子数组平铺到2D中来构造所需的数组,并使用所需的列表形式。其可以使用一些基本的列表解析来构造: