原来想要是先这个变换,查了一下tensorflow还真有,但是看上去很少有人用所以记录一下
tf.roll(
input, shift, axis, name=None
)
在tf1里是
tf.manip.roll(
input,
shift,
axis
)
示例
# 't' is [0, 1, 2, 3, 4]
roll(t, shift=2, axis=0) ==> [3, 4, 0, 1, 2]
# shifting along multiple dimensions
# 't' is [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]
roll(t, shift=[1, -2], axis=[0, 1]) ==> [[7, 8, 9, 5, 6], [2, 3, 4, 0, 1]]
# shifting along the same axis multiple times
# 't' is [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]
roll(t, shift=[2, -3], axis=[1, 1]) ==> [[1, 2, 3, 4, 0], [6, 7, 8, 9, 5]]
参数介绍及参考:
https://tensorflow.google.cn/api_docs/python/tf/roll#args