tf.transpose()的用法

一、tensorflow官方文档内容

transpose(
    a,
    perm=None,
    name='transpose'
)

Defined in tensorflow/python/ops/array_ops.py.

See the guides: Math > Matrix Math FunctionsTensor Transformations > Slicing and Joining

Transposes a. Permutes the dimensions according to perm.

The returned tensor's dimension i will correspond to the input dimension perm[i]. If perm is not given, it is set to (n-1...0), where n is the rank of the input tensor. Hence by default, this operation performs a regular matrix transpose on 2-D input Tensors.

For example:  

# 'x' is [[1 2 3]
#         [4 5 6]]
tf.transpose(x) ==> [[1 4]
                     [2 5]
                     [3 6]]
 
# Equivalently
tf.transpose(x, perm=[1, 0]) ==> [[1 4]
                                  [2 5]
                                  [3 6]]
 
# 'perm' is more useful for n-dimensional tensors, for n > 2
# 'x' is   [[[1  2  3]
#            [4  5  6]]
#           [[7  8  9]
#            [10 11 12]]]
# Take the transpose of the matrices in dimension-0
tf.transpose(x, perm=[0, 2, 1]) ==> [[[1  4]
                                      [2  5]
                                      [3  6]]
 
                                     [[7 10]
                                      [8 11]
                                      [9 12]]]

Args:

  • a: A Tensor.
  • perm: A permutation of the dimensions of a.
  • name: A name for the operation (optional).

Returns:

A transposed Tensor.

二、中文翻译

transpose(
    a,
    perm=None,
    name='transpose'
)

Defined in tensorflow/python/ops/array_ops.py.

See the guides: Math > Matrix Math FunctionsTensor Transformations > Slicing and Joining

a的转置是根据 perm 的设定值来进行的。 

返回数组的 dimension(尺寸、维度) i与输入的 perm[i]的维度相一致。如果未给定perm,默认设置为 (n-1...0),这里的 n 值是输入变量的 rank 。因此默认情况下,这个操作执行了一个正规(regular)的2维矩形的转置。

例子:

# 'x' is [[1 2 3]
#         [4 5 6]]
tf.transpose(x) ==> [[1 4]
                     [2 5]
                     [3 6]]
 
# Equivalently(等价于)
tf.transpose(x, perm=[1, 0]) ==> [[1 4]
                                  [2 5]
                                  [3 6]]
 
# 'perm' is more useful for n-dimensional tensors, for n > 2
# 'x' is   [[[1  2  3]
#            [4  5  6]]
#           [[7  8  9]
#            [10 11 12]]]
# Take the transpose of the matrices in dimension-0
tf.transpose(x, perm=[0, 2, 1]) ==> [[[1  4]
                                      [2  5]
                                      [3  6]]
 
                                     [[7 10]
                                      [8 11]
                                      [9 12]]]

参数:  

  • a: a 是一个张量(Tensor)
  • perm: perm 是 a 维度的置换
  • name:操作的名称(可选).

返回值:

 返回的是一个转置的张量。

三、解释

tf.transpose(input, [dimension_1, dimenaion_2,..,dimension_n]):这个函数主要适用于交换输入张量的不同维度用的,如果输入张量是二维,就相当是转置。dimension_n是整数,如果张量是三维,就是用0,1,2来表示。这个列表里的每个数对应相应的维度。如果是[2,1,0],就把输入张量的第三维度和第一维度交换。 

 
----------------------------------
参考链接:
  1、 tf.transpose函数的用法: https://i.cnblogs.com/EditPosts.aspx?opt=1
  2、 tensorflow中的不懂得知识点——转置函数 transpose : http://blog.csdn.net/u010417185/article/details/51900441
  3、tensorflow官方文档 https://www.tensorflow.org/versions/r1.3/api_docs/python/tf/transpose

deep_learning_Function_tensorflow_transpose()的更多相关文章

随机推荐

  1. Js实现京东无延迟菜单效果(demo) 慕课网

    先来理清思路:1.开发基本的菜单结构 2.开发普通的二级菜单效果 3.假如延迟解决移动问题 切换子菜单时候,用setTimeout设置延迟 debounce去抖技 在事件被频繁触发是,只执行一次处理 ...

  2. Selenium 2自动化测试实战23(窗口截图)

    一.窗口截图 WebDriver提供了截图函数get_screenshot_as_file()来截取当前窗口. # -*- coding: utf-8 -*- from selenium import ...

  3. c# 匿名类型获取值

    代码片段: 读取 new{ ....} 方法1:转换为json对象 dynamic model = SaleOrderServices.GetGiftOrderById(WebHelper.GetQu ...

  4. spring使用@Async注解异步处理

    1. 何为异步调用?在解释异步调用之前,我们先来看同步调用的定义:同步就是整个处理过程顺序执行,当各个过程都执行完毕,并返回结果. 异步调用则是只是发送了调用的指令,调用者无需等待被调用的方法完全执行 ...

  5. ModelAndView及页面转发

    1.ModelAndView springMVC中返回值如果是ModelAndView,则其既包含模型数据信息,也包含视图信息. 在处理方法中可以使用ModelAndView对象的方法添加模型数据:a ...

  6. UBT框架加解密工具项目 UBT.Framework.Encryption

    DESEncrypt.cs //==================================================================================== ...

  7. 【.NET】Browser Link: Failed to deserialize JSON in Browser Link call

    问题 VS2013中调试程序发现,在浏览器控制台输出如下截图代码:

  8. 【POJ - 3087】Shuffle'm Up(模拟)

    Shuffle'm Up 直接写中文了 Descriptions: 给定两个长度为len的字符串s1和s2, 接着给出一个长度为len*2的字符串s12. 将字符串s1和s2通过一定的变换变成s12, ...

  9. KVM虚拟化原理

    CPU虚拟化 KVM虚拟化是需要硬件支持的.我们可以用 egrep -o '(vmx|svm)' /proc/cpuinfo 来查看是否支持CPU虚拟化. 虚拟机中每一个vCPU对应qemu-kvm中 ...

  10. 云计算Openstack介绍(1)

    一.云计算的前世今生 所有的新事物都不是突然冒出来的,都有前世和今生.云计算也是IT技术不断发展的产物. 要理解云计算,需要对IT系统架构的发展过程有所认识. 请看下 IT系统架构的发展到目前为止大致 ...