mindspore.dataset.transforms.Duplicate
- class mindspore.dataset.transforms.Duplicate[source]
Duplicate the input tensor to output, only support transform one column each time.
- Raises
RuntimeError – If given tensor has two columns.
- Supported Platforms:
CPU
Examples
>>> 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