mindspore.ops.Pad

class mindspore.ops.Pad(paddings)[source]

Pads the input tensor according to the paddings. For example, to pad only the last dimension of the input tensor, then pad has the form (padding_left,padding_right); to pad the last 2 dimensions of the input tensor, then use (padding_left,padding_right, padding_top,padding_bottom); to pad the last 3 dimensions, use (padding_left,padding_right, padding_top,padding_bottom padding_front,padding_back).

 input_x_shape=(N1,N2,...,Nn)output_shape = (N1+paddings[0,0]+paddings[0,1],N2+paddings[1,0]+paddings[1,1],...,Nn+paddings[n1,0]+paddings[n1,1])
Parameters

paddings (tuple) – The shape of parameter paddings is (N, 2). N is the rank of input data. All elements of paddings are int type. For the input in D th dimension, paddings[D, 0] indicates how many sizes to be extended ahead of the input tensor in the D th dimension, and paddings[D, 1] indicates how many sizes to be extended behind the input tensor in the D th dimension.

Inputs:
  • input_x (Tensor) - Tensor of shape (N,), where means, any number of additional dimensions.

Outputs:

Tensor, the tensor after padding.

Raises
  • TypeError – If paddings is not a tuple.

  • TypeError – If input_x is not a Tensor.

  • ValueError – If shape of paddings is not (N,2).

  • ValueError – If paddings.size is not equal to 2 * len(input_x).

Supported Platforms:

Ascend GPU CPU

Examples

>>> input_x = Tensor(np.array([[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]]), mindspore.float32)
>>> pad_op = ops.Pad(((1, 2), (2, 1)))
>>> output = pad_op(input_x)
>>> print(output)
[[ 0.   0.   0.   0.   0.   0. ]
 [ 0.   0.  -0.1  0.3  3.6  0. ]
 [ 0.   0.   0.4  0.5 -3.2  0. ]
 [ 0.   0.   0.   0.   0.   0. ]
 [ 0.   0.   0.   0.   0.   0. ]]