squeeze_cn.rst 1.9 KB
Newer Older
1
.. _cn_api_paddle_tensor_squeeze
T
tianshuo78520a 已提交
2 3
squeeze
-------------------------------
4

L
Leo Chen 已提交
5
.. py:function:: paddle.tensor.squeeze(x, axis=None, name=None)
6

S
swtkiwi 已提交
7

L
Leo Chen 已提交
8
该OP会删除输入Tensor的Shape中尺寸为1的维度。如果指定了axis,则会删除axis中指定的尺寸为1的维度。如果没有指定axis,那么所有等于1的维度都会被删除。
S
swtkiwi 已提交
9

L
Leo Chen 已提交
10
.. code-block:: text
S
swtkiwi 已提交
11

L
Leo Chen 已提交
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
    Case 1:

        Input:
        x.shape = [1, 3, 1, 5]  # If axis is not provided, all dims equal of size 1 will be removed.
        axis = None
        Output:
        out.shape = [3, 5]

    Case 2:

        Input:
        x.shape = [1, 3, 1, 5]  # If axis is provided, it will remove the dimension(s) by given axis that of size 1.
        axis = 0
        Output:
        out.shape = [3, 1, 5]
    
    Case 3:

        Input:
        x.shape = [1, 3, 1, 5]  # If the dimension of one given axis (3) is not of size 1, the dimension remain unchanged. 
        axis = [0, 2, 3]
        Output:
        out.shape = [3, 5]

    Case 4:

        Input:
        x.shape = [1, 3, 1, 5]  # If axis is negative, axis = axis + ndim (number of dimensions in x). 
        axis = [-2]
        Output:
        out.shape = [1, 3, 5]
43 44

**参数**:
L
Leo Chen 已提交
45 46 47
        - **x** (Tensor) - 输入的 `Tensor` ,数据类型为:float32、float64、bool、int8、int32、int64。
        - **axis** (int|list|tuple, 可选) - 输入一个或一列整数,代表要压缩的轴。axis的范围: [−ndim(x), ndim(x))] 。 如果axis为负数, 则axis=axis+ndim(x) 。
        - **name** (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。
48

L
Leo Chen 已提交
49
**返回**:返回对维度进行压缩后的Tensor,数据类型与输入Tensor一致。
50

L
Leo Chen 已提交
51
**返回类型**:Tensor
52 53 54 55 56 57

**代码示例**:

.. code-block:: python

    import paddle
L
Leo Chen 已提交
58 59 60 61 62 63

    paddle.disable_static()
    
    x = paddle.rand([5, 1, 10])
    output = paddle.squeeze(x, axis=1)
    # output.shape [5, 10]