我有一个4维张量x
。计算6维张量y
如下:
x = np.random.randn(64, 28, 28, 1)
strided_shape = 64, 26, 26, 3, 3, 1
y = numpy.lib.stride_tricks.as_strided(x, strided_shape, strides=(x.strides[0], x.strides[1], x.strides[2], x.strides[1], x.strides[2], x.strides[3]))
strided_shape
通常可以是任何形状,只要第一个和最后一个维度与 x
相同(这只是一个具体的例子)。
我的问题是,是否可以使用y
(以及x.shape
和 x.strides
这些元组)通过再次使用 as_strided
、reshape
、sum
等操作来恢复原始张量 x
?注意:我实际上并不打算将该过程应用于 y
本身;而是想对形状与y
相同的张量执行该过程。
numpy.lib.stride_tricks.as_strided
是相当冒险的,使用np.reshape
和/或np.tile
是否足够?这样可能更容易恢复。 - Dorian