mindspore.ops.StridedSlice
- class mindspore.ops.StridedSlice(begin_mask=0, end_mask=0, ellipsis_mask=0, new_axis_mask=0, shrink_axis_mask=0)[源代码]
对输入Tensor根据步长和索引进行切片提取。
更多参考详见
mindspore.ops.strided_slice()
。- 参数:
begin_mask (int,可选) - 表示切片的起始索引掩码。默认值:0。
end_mask (int,可选) - 表示切片的结束索引掩码。默认值:0。
ellipsis_mask (int,可选) - 维度掩码值为1说明不需要进行切片操作。为int型掩码。默认值:0。
new_axis_mask (int,可选) - 表示切片的新增维度掩码。默认值:0。
shrink_axis_mask (int,可选) - 表示切片的收缩维度掩码。为int型掩码。默认值:0。
- 输入:
input_x (Tensor) - 需要切片处理的输入Tensor。
begin (tuple[int]) - 指定开始切片的索引。仅支持大于或等于0的int值。
end (tuple[int]) - 指定结束切片的索引。仅支持大于0的int值。
strides (tuple[int]) - 指定各维度切片的步长。输入为一个tuple,仅支持int值。strides 的元素必须非零。可能为负值,这会导致反向切片。
- 输出:
返回根据起始索引、结束索引和步长进行提取出的切片Tensor。
- 支持平台:
Ascend
GPU
CPU
样例:
>>> input_x = Tensor([[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]], ... [[5, 5, 5], [6, 6, 6]]], mindspore.float32) >>> # [[[1. 1. 1.] >>> # [2. 2. 2.]] >>> # >>> # [[3. 3. 3.] >>> # [4. 4. 4.]] >>> # >>> # [[5. 5. 5.] >>> # [6. 6. 6.]]] >>> # In order to visually view the multi-dimensional array, write the above as follows: >>> # [ >>> # [ >>> # [1,1,1] >>> # [2,2,2] >>> # ] >>> # [ >>> # [3,3,3] >>> # [4,4,4] >>> # ] >>> # [ >>> # [5,5,5] >>> # [6,6,6] >>> # ] >>> # ] >>> strided_slice = ops.StridedSlice() >>> output = strided_slice(input_x, (1, 0, 2), (3, 1, 3), (1, 1, 1)) >>> # Take this " output = strided_slice(input_x, (1, 0, 2), (3, 1, 3), (1, 1, 1)) " as an example, >>> # start = [1, 0, 2] , end = [3, 1, 3], stride = [1, 1, 1], Find a segment of (start, end), >>> # note that end is an open interval >>> # To facilitate understanding, this operator can be divided into three steps: >>> # Step 1: Calculation of the first dimension: >>> # start = 1, end = 3, stride = 1, So can take 1st, 2nd rows, and then gets the final output at this time. >>> # output_1th = >>> # [ >>> # [ >>> # [3,3,3] >>> # [4,4,4] >>> # ] >>> # [ >>> # [5,5,5] >>> # [6,6,6] >>> # ] >>> # ] >>> # Step 2: Calculation of the second dimension >>> # 2nd dimension, start = 0, end = 1, stride = 1. So only 0th rows can be taken, and the output at this time. >>> # output_2nd = >>> # [ >>> # [ >>> # [3,3,3] >>> # ] >>> # [ >>> # [5,5,5] >>> # ] >>> # ] >>> # Step 3: Calculation of the third dimension >>> # 3nd dimension,start = 2, end = 3, stride = 1, So can take 2th cols, >>> # and you get the final output at this time. >>> # output_3ed = >>> # [ >>> # [ >>> # [3] >>> # ] >>> # [ >>> # [5] >>> # ] >>> # ] >>> # The final output after finishing is: >>> print(output) [[[3.]] [[5.]]] >>> # another example like : >>> output = strided_slice(input_x, (1, 0, 0), (2, 1, 3), (1, 1, 1)) >>> print(output) [[[3. 3. 3.]]]