codecamp

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

tf.reverse_v2 函数

reverse_v2(
    tensor,
    axis,
    name=None
)

参见指南:张量变换>分割和连接

反转张量的特定维度.

需要注意的是tf.reverse现在已经改变了为TF 1.0准备的行为.tf.reverse_v2目前是一个别名,在TF 1.0之前将被弃用.

给定一个tensor和一个int32型张量axis,表示一组要反转的tensor的维度.此操作反转存在j s.t. axis[j] == i的每个维度i.

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:操作的名称(可选).

返回:

该函数将返回一个Tensor,它与tensor有相同的类型和形状.

TensorFlow函数:tf.reverse_sequence
TensorFlow:tf.rint函数
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

TensorFlow 函数介绍

TensorFlow 函数模块:tf

TensorFlow的image模块

TensorFlow使用之tf.io

TensorFlow使用之tf.keras

TensorFlow函数教程:tf.keras.applications

TensorFlow函数教程:tf.keras.backend

TensorFlow使用之tf.metrics

TensorFlow使用之tf.nn

TensorFlow使用之tf.python_io

TensorFlow 功能函数

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }