mindspore.dataset.text.SlidingWindow
- class mindspore.dataset.text.SlidingWindow(width, axis=0)[source]
Construct a tensor from given data (only support 1-D for now), where each element in the dimension axis is a slice of data starting at the corresponding position, with a specified width.
- Parameters
- Raises
TypeError – If width is not of type int.
ValueError – If value of width is not positive.
TypeError – If axis is not of type int.
- Supported Platforms:
CPU
Examples
>>> import mindspore.dataset as ds >>> import mindspore.dataset.text as text >>> >>> dataset = ds.NumpySlicesDataset(data=[[1, 2, 3, 4, 5]], column_names="col1") >>> # Data before >>> # | col1 | >>> # +--------------+ >>> # | [[1, 2, 3, 4, 5]] | >>> # +--------------+ >>> dataset = dataset.map(operations=text.SlidingWindow(3, 0)) >>> # Data after >>> # | col1 | >>> # +--------------+ >>> # | [[1, 2, 3], | >>> # | [2, 3, 4], | >>> # | [3, 4, 5]] | >>> # +--------------+
- Tutorial Examples: