tf.roll
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中用的比較多
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
- 上一篇: tf.reverse_sequence
- 下一篇: sql IFNULL