codecamp

TensorFlow:tf.reverse函数

tf.reverse 函数

reverse(
    tensor,
    axis,
    name=None
)

定义在:tensorflow/python/ops/array_ops.py.

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

反转张量的特定维度.

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

给定一个tensor和一个int32类型的张量axis,以表示要反转的tensor的一组维度.此操作反转每个维度 i ,其中存在 j,例如:axis[j] == 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.reshape函数重塑张量
TensorFlow函数:tf.reverse_sequence
温馨提示
下载编程狮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; }