shape

paddle.fluid.layers.nn. shape ( input ) [source]
Alias_main

paddle.shape :alias: paddle.shape,paddle.tensor.shape,paddle.tensor.attribute.shape :old_api: paddle.fluid.layers.shape

Shape Layer

Get the shape of the input.

Case1:
    Given N-D Tensor:
        input = [ [1, 2, 3, 4], [5, 6, 7, 8] ]

    Then:
        input.shape = [2, 4]

Case2:
    Given SelectedRows:
        input.rows = [0, 4, 19]
        input.height = 20
        input.value = [ [1, 2], [3, 4], [5, 6] ]  # inner tensor
    Then:
        input.shape = [3, 2]
Parameters

input (Variable) – The input can be N-D Tensor or SelectedRows with data type bool, float16, float32, float64, int32, int64. If input variable is type of SelectedRows, returns the shape of it’s inner tensor.

Returns

The shape of the input variable.

Return type

Variable (Tensor)

Examples

import paddle.fluid as fluid
import numpy as np

inputs = fluid.data(name="x", shape=[3, 100, 100], dtype="float32")
output = fluid.layers.shape(inputs)

exe = fluid.Executor(fluid.CPUPlace())
exe.run(fluid.default_startup_program())

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

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