《道德观察(日播版)》 20180324 虚惊一场

paddle. shape ( input: Tensor ) Tensor [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 (Tensor) – 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

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=int64)]

Used in the guide/tutorials?