mindspore.dataset.transforms.c_transforms.Slice
- class mindspore.dataset.transforms.c_transforms.Slice(*slices)[source]
- Slice operation to extract a tensor out using the given n slices. - The functionality of Slice is similar to NumPy’s indexing feature (Currently only rank-1 tensors are supported). - Parameters
- slices (Union[int, list[int], slice, None, Ellipsis]) – - Maximum n number of arguments to slice a tensor of rank n . One object in slices can be one of: - int: Slice this index only along the first dimension. Negative index is supported.
- list(int): Slice these indices along the first dimension. Negative indices are supported.
- slice: Slice the generated indices from the slice object along the first dimension. Similar to start:stop:step.
- None: Slice the whole dimension. Similar to- [:]in Python indexing.
- Ellipsis: Slice the whole dimension, same result with None.
 
 - Examples - >>> # 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=c_transforms.Slice(slice(1,3))) >>> # Data after >>> # | col | >>> # +---------+ >>> # | [2,3] | >>> # +---------|