shape

paddle. shape ( input ) [source]

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, bfloat16, 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 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)]

Used in the guide/tutorials