mindspore.dataset.transforms.Slice

View Source On Gitee
class mindspore.dataset.transforms.Slice(*slices)[source]

Extract a slice from the input.

Currently, only 1-D input is supported.

Parameters

slices (Union[int, list[int], slice, Ellipsis]) – The desired slice. If the input type is int, it will slice the element with the specified index value. Negative index is also supported. If the input type is list[int], it will slice all the elements with the specified index values. Negative index is also supported. If the input type is slice , it will slice according to its specified start position, stop position and step size. If the input type is Ellipsis , all elements will be sliced. If the input is None, all elements will be sliced.

Raises

TypeError – If slices is not of type Union[int, list[int], slice, Ellipsis].

Supported Platforms:

CPU

Examples

>>> import mindspore.dataset as ds
>>> import mindspore.dataset.transforms as transforms
>>> # Data before
>>> # |   col   |
>>> # +---------+
>>> # | [1,2,3] |
>>> # +---------|
>>> data = [[1, 2, 3]]
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["col"])
>>> # slice indices 1 and 2 only
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms.Slice(slice(1,3)))
>>> # Data after
>>> # |   col   |
>>> # +---------+
>>> # |  [2,3]  |
>>> # +---------|