mindspore.dataset.transforms.Concatenate

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

Tensor operation that concatenates all columns into a single tensor, only 1D tenspr is supported.

Parameters
  • axis (int, optional) – Concatenate the tensors along given axis. Default: 0.

  • prepend (numpy.ndarray, optional) – NumPy array to be prepended to the already concatenated tensors. Default: None.

  • append (numpy.ndarray, optional) – NumPy array to be appended to the already concatenated tensors. Default: None.

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 mindspore.dataset as ds
>>> import mindspore.dataset.transforms as transforms
>>> import numpy as np
>>>
>>> # concatenate string
>>> prepend_tensor = np.array(["dw", "df"], dtype='S')
>>> append_tensor = np.array(["dwsdf", "df"], dtype='S')
>>> concatenate_op = transforms.Concatenate(0, prepend_tensor, append_tensor)
>>> data = [["This","is","a","string"]]
>>> dataset = ds.NumpySlicesDataset(data)
>>> dataset = dataset.map(operations=concatenate_op)