mindspore.dataset.transforms.PadEnd

class mindspore.dataset.transforms.PadEnd(pad_shape, pad_value=None)[source]

Pad input tensor according to pad_shape, input tensor needs to have same rank.

Parameters
  • pad_shape (list(int)) – List of integers representing the shape needed. Dimensions that set to None will not be padded (i.e., original dim will be used). Shorter dimensions will truncate the values.

  • pad_value (Union[str, bytes, int, float, bool], optional) – Value used to pad. Default: None. Default to 0 in case of tensors of Numbers, or empty string in case of tensors of strings.

Raises
  • TypeError – If pad_shape is not of type list.

  • TypeError – If pad_value is not of type str, float, bool, int or bytes.

  • TypeError – If elements of pad_shape is not of type int.

  • ValueError – If elements of pad_shape is not of positive.

Supported Platforms:

CPU

Examples

>>> import mindspore.dataset as ds
>>> import mindspore.dataset.transforms as transforms
>>>
>>> # Use the transform in dataset pipeline mode
>>> # Data before
>>> # |   col   |
>>> # +---------+
>>> # | [1,2,3] |
>>> # +---------|
>>> data = [[1, 2, 3]]
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["col"])
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms.PadEnd(pad_shape=[4], pad_value=10))
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
...     print(item["col"].shape, item["col"].dtype)
...     break
(4,) int64
>>> # Data after
>>> # |    col     |
>>> # +------------+
>>> # | [1,2,3,10] |
>>> # +------------|
>>>
>>> # Use the transform in eager mode
>>> data = [1, 2, 3]
>>> output = transforms.PadEnd(pad_shape=[4], pad_value=10)(data)
>>> print(output.shape, output.dtype)
(4,) int64