t =[0, 1, 2, 3, 4]
tf.roll(t, shift=2, axis=0)
<tf.Tensor: shape=(5,), dtype=int32, numpy=array([3, 4, 0, 1, 2], dtype=int32)>
这里的 axis=[0]比较奇怪,0轴表示列,1轴表示行
t=[[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]
t1=tf.roll(t, shift=[1], axis=[0])
print('t1=',t1)
t2=tf.roll(t1, shift=[ -2], axis=[ 1])
print('t2=',t2)
t1= tf.Tensor(
[[5 6 7 8 9]
[0 1 2 3 4]], shape=(2, 5), dtype=int32)
t2= tf.Tensor(
[[7 8 9 5 6]
[2 3 4 0 1]], shape=(2, 5), dtype=int32)
可以把两部合并成一步执行
tf.roll(t, shift=[1, -2], axis=[0, 1])
==> [[7, 8, 9, 5, 6], [2, 3, 4, 0, 1]]
这个函数在deepdream中用的比较多