0
我有一个Theano tensor3
(即,3维阵列)x
:移基于偏移矢量tensor3元素的位置
[[[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]]
[[12 13 14 15]
[16 17 18 19]
[20 21 22 23]]]
以及一个Theano向量(即,一维阵列)y
,我们将参考作为“偏移”向量,因为它指定了期望的偏移:
[2, 1]
欲转移基于矢量y
的x
元素的位置,从而使输出如下(在第二维进行变速):
[[[ a b c d]
[ e f g h]
[ 0 1 2 3]]
[[ i j k l]
[12 13 14 15]
[16 17 18 19]]]
其中a
,b
,...,l
可以是任何数目。
例如,一个有效的输出可能是:
[[[ 0 0 0 0]
[ 0 0 0 0]
[ 0 1 2 3]]
[[ 0 0 0 0]
[12 13 14 15]
[16 17 18 19]]]
另一种有效的输出可能是:
[[[ 4 5 6 7]
[ 8 9 10 11]
[ 0 1 2 3]]
[[20 21 22 23]
[12 13 14 15]
[16 17 18 19]]]
我知道的功能theano.tensor.roll(x, shift, axis=None)
的,但是shift
只能拿一个标量作为输入,即它移动所有具有相同偏移量的元素。
例如,代码:
import theano.tensor
from theano import shared
import numpy as np
x = shared(np.arange(24).reshape((2,3,4)))
print('theano.tensor.roll(x, 2, axis=1).eval(): \n{0}'.
format(theano.tensor.roll(x, 2, axis=1).eval()))
输出:
theano.tensor.roll(x, 2, axis=1).eval():
[[[ 4 5 6 7]
[ 8 9 10 11]
[ 0 1 2 3]]
[[16 17 18 19]
[20 21 22 23]
[12 13 14 15]]]
这不是我想要的。
如何根据偏移矢量移动tensor3
元素的位置? (注意在这个例子中提供的代码中,为了方便起见,tensor3
是一个共享变量,但在我的实际代码中它将是一个符号变量)