# TensorFlow：tf.reverse函数

## tf.reverse 函数

``````reverse(
tensor,
axis,
name=None
)``````

tensor可以有多达8个维度.指定的维数axis可以是0或更多的条目.如果多次指定索引,则会引发InvalidArgument错误.

``````# tensor 't' is [[[[ 0,  1,  2,  3],
#                  [ 4,  5,  6,  7],
#                  [ 8,  9, 10, 11]],
#                 [[12, 13, 14, 15],
#                  [16, 17, 18, 19],
#                  [20, 21, 22, 23]]]]
# tensor 't' shape is [1, 2, 3, 4]

# 'dims' is [3] or 'dims' is -1
reverse(t, dims) ==> [[[[ 3,  2,  1,  0],
[ 7,  6,  5,  4],
[ 11, 10, 9, 8]],
[[15, 14, 13, 12],
[19, 18, 17, 16],
[23, 22, 21, 20]]]]

# 'dims' is '[1]' (or 'dims' is '[-3]')
reverse(t, dims) ==> [[[[12, 13, 14, 15],
[16, 17, 18, 19],
[20, 21, 22, 23]
[[ 0,  1,  2,  3],
[ 4,  5,  6,  7],
[ 8,  9, 10, 11]]]]

# 'dims' is '[2]' (or 'dims' is '[-2]')
reverse(t, dims) ==> [[[[8, 9, 10, 11],
[4, 5, 6, 7],
[0, 1, 2, 3]]
[[20, 21, 22, 23],
[16, 17, 18, 19],
[12, 13, 14, 15]]]]``````

• tensor：一个Tensor.必须是下列类型之一：uint8,int8,uint16,int16,int32,int64,bool,half,float32,float64,complex64,complex128,string.可以达到8-D.
• axis：一个 Tensor.必须是以下类型之一：int32,int64；1-d.要反转的维度的指数.必须在范围[-rank(tensor), rank(tensor))内.
• name：操作的名称(可选).

App下载