mindspore.dataset.transforms.Concatenate

class mindspore.dataset.transforms.Concatenate(axis=0, prepend=None, append=None)[source]

Concatenate data with input array along given axis, only 1D data is supported.

Parameters
  • axis (int, optional) – The axis along which the arrays will be concatenated. Default: 0.

  • prepend (numpy.ndarray, optional) – NumPy array to be prepended to the input array. Default: None, not to prepend array.

  • append (numpy.ndarray, optional) – NumPy array to be appended to the input array. Default: None, not to append array.

Raises
  • TypeError – If axis is not of type int.

  • TypeError – If prepend is not of type numpy.ndarray.

  • TypeError – If append is not of type numpy.ndarray.

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
>>> # concatenate string
>>> prepend_tensor = np.array(["dw", "df"])
>>> append_tensor = np.array(["dwsdf", "df"])
>>> concatenate_op = transforms.Concatenate(0, prepend_tensor, append_tensor)
>>> data = [["This","is","a","string"]]
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data)
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=concatenate_op)
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
...     print(item["column_0"].shape, item["column_0"].dtype)
(8,) <U6
>>>
>>> # Use the transform in eager mode
>>> data = np.array([1, 2, 3])
>>> prepend_tensor = np.array([10, 20])
>>> append_tensor = np.array([100])
>>> output = transforms.Concatenate(0, prepend_tensor, append_tensor)(data)
>>> print(output.shape, output.dtype)
(6,) int64