mindspore.dataset.transforms.Duplicate

查看源文件
class mindspore.dataset.transforms.Duplicate[源代码]

将输入的数据列复制得到新的数据列,每次仅可以输入1个数据列进行复制。

异常:
  • RuntimeError - 输入数据列数量大于1。

支持平台:

CPU

样例:

>>> import numpy as np
>>> import mindspore.dataset as ds
>>> import mindspore.dataset.transforms as transforms
>>>
>>> # Use the transform in dataset pipeline mode
>>> # Data before
>>> # |  x      |
>>> # +---------+
>>> # | [1,2,3] |
>>> # +---------+
>>> data = [[1,2,3]]
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["x"])
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms.Duplicate(),
...                                                 input_columns=["x"],
...                                                 output_columns=["x", "y"])
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
...     print(item["x"].shape, item["x"].dtype)
...     print(item["y"].shape, item["y"].dtype)
(3,) int64
(3,) int64
>>> # Data after
>>> # |  x      |  y      |
>>> # +---------+---------+
>>> # | [1,2,3] | [1,2,3] |
>>> # +---------+---------+
>>>
>>> # Use the transform in eager mode
>>> data = [1, 2, 3]
>>> output = transforms.Duplicate()(data)
>>> print(np.array(output).shape, np.array(output).dtype)
(2, 3) int64