t_cn.rst 1.4 KB
Newer Older
1 2
.. _cn_api_paddle_tensor_t:

T
tianshuo78520a 已提交
3 4
t
-------------------------------
5

L
Leo Chen 已提交
6
.. py:function:: paddle.fluid.layers.t(input, name=None)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

该OP对小于等于2维的Tensor进行数据转置。0维和1维Tensor返回本身,2维Tensor等价于perm设置为0,1的 :ref:`cn_api_fluid_layers_transpose` 函数。

参数:
    - **input** (Variable) - 输入:N维(N<=2)Tensor,可选的数据类型为float16, float32, float64, int32, int64。
    - **name** (str, 可选)- 该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` ,默认值为None

返回: N维Tensor

返回类型:Variable

**示例**:

.. code-block:: python

        # 例1 (0-D tensor)
        x = tensor([0.79])
L
Leo Chen 已提交
24
        fluid.layers.t(x) = tensor([0.79])
25 26 27

        # 例2 (1-D tensor)
        x = tensor([0.79, 0.84, 0.32])
L
Leo Chen 已提交
28
        fluid.layers.t(x) = tensor([0.79, 0.84, 0.32])
29 30 31 32

        # 例3 (2-D tensor)
        x = tensor([0.79, 0.84, 0.32],
                    [0.64, 0.14, 0.57])
L
Leo Chen 已提交
33
        fluid.layers.t(x) = tensor([0.79, 0.64],
34 35 36 37 38 39 40 41 42 43 44
                            [0.84, 0.14],
                            [0.32, 0.57])


**代码示例**:

.. code-block:: python

    import paddle
    import paddle.fluid as fluid
    x = fluid.data(name='x', shape=[2, 3], dtype='float32')
L
Leo Chen 已提交
45
    x_transposed = fluid.layers.t(x) # paddle.t 等价于 paddle.tensor.t
46 47 48
    print(x_transposed.shape)
    #(3L, 2L)