shape

paddle. shape ( input ) [源代码]

shape 层。

获得输入 Tensor 或 SelectedRows 的 shape。

示例 1:
    输入是 N-D Tensor 类型:
        input = [ [1, 2, 3, 4], [5, 6, 7, 8] ]

    输出 shape:
        input.shape = [2, 4]

示例 2:
    输入是 SelectedRows 类型:
        input.rows = [0, 4, 19]
        input.height = 20
        input.value = [ [1, 2], [3, 4], [5, 6] ]  # inner tensor
    输出 shape:
        input.shape = [3, 2]

参数

  • input (Variable)- 输入的多维 Tensor 或 SelectedRows,数据类型为 bool, bfloat16,float16,float32,float64,int32,int64。如果输入是 SelectedRows 类型,则返回其内部持有 Tensor 的 shape。

返回

Tensor,表示输入 Tensor 或 SelectedRows 的 shape。

代码示例

>>> import numpy as np
>>> import paddle
>>> paddle.enable_static()

>>> inputs = paddle.static.data(name="x", shape=[3, 100, 100], dtype="float32")
>>> output = paddle.shape(inputs)

>>> exe = paddle.static.Executor(paddle.CPUPlace())
>>> exe.run(paddle.static.default_startup_program())

>>> img = np.ones((3, 100, 100)).astype(np.float32)

>>> res = exe.run(paddle.static.default_main_program(), feed={'x':img}, fetch_list=[output])
>>> print(res)
[array([  3, 100, 100], dtype=int32)]

使用本API的教程文档