# tf.reverse_v2函数：反转张量的特定维度

## tf.reverse_v2 函数

``````reverse_v2(
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下载