pad_constant_like¶
- paddle.fluid.layers.nn. pad_constant_like ( x, y, pad_value=0.0, name=None ) [source]
-
Pad
y
withpad_value
, the number of values padded to the edges of each axis is specified by the difference of the shape ofx
andy
. ((0, shape_x_0 - shape_y_0), … (0, shape_x_n - shape_y_n)) specify padding widths for each axis. The input should be a k-D tensor(k > 0 and k < 7).See below for an example.
Given: X = [[[[ 0, 1, 2], [ 3, 4, 5]], [[ 6, 7, 8], [ 9, 10, 11]], [[12, 13, 14], [15, 16, 17]]], [[[18, 19, 20], [21, 22, 23]], [[24, 25, 26], [27, 28, 29]], [[30, 31, 32], [33, 34, 35]]]] X.shape = (2, 3, 2, 3) Y = [[[[35, 36, 37]], [[38, 39, 40]], [[41, 42, 43]]]] Y.shape = (1, 3, 1, 3) And pad_value = 0. Return: Out = [[[[35, 36, 37], [ 0, 0, 0]], [[38, 39, 40], [ 0, 0, 0]], [[41, 42, 43], [ 0, 0, 0]]], [[[ 0, 0, 0], [ 0, 0, 0]], [[ 0, 0, 0], [ 0, 0, 0]], [[ 0, 0, 0], [ 0, 0, 0]]]] Out.shape = [2, 3, 2, 3]
- Parameters
-
x (Variable) – Tensor, its shape specifies the shape of output.
y (Variable) – Tensor, its rank is the same with
x
, and for each dimension \(i\) , \(y\_shape[i] <= x\_shape[i]\) . The data type can be float32 or float64.pad_value (float) – The constant value used to pad.
name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name
- Returns
-
The padded tensor, with the same shape as
x
and the same data type asy
- Return Type:
-
Variable
Examples
# x is a rank 4 tensor variable, x.shape = (2, 3, 2, 3) # y is a rank 4 tensor variable, y.shape = (1, 3, 1, 3) import paddle.fluid as fluid x = fluid.data(name='x', shape=[2,3,2,3], dtype='float32') y = fluid.data(name='y', shape=[1,3,1,3], dtype='float32') out = fluid.layers.pad_constant_like(x=x, y=y, pad_value=0.) # out is a rank 4 tensor variable, and out.shape = [2, 3 ,2 , 3]