文档反馈

问题文档片段

问题文档片段包含公式时,显示为空格。

提交类型
issue

有点复杂...

找人问问吧。

请选择提交类型

问题类型
规范和低错类

- 规范和低错类:

- 错别字或拼写错误,标点符号使用错误、公式错误或显示异常。

- 链接错误、空单元格、格式错误。

- 英文中包含中文字符。

- 界面和描述不一致,但不影响操作。

- 表述不通顺,但不影响理解。

- 版本号不匹配:如软件包名称、界面版本号。

易用性

- 易用性:

- 关键步骤错误或缺失,无法指导用户完成任务。

- 缺少主要功能描述、关键词解释、必要前提条件、注意事项等。

- 描述内容存在歧义指代不明、上下文矛盾。

- 逻辑不清晰,该分类、分项、分步骤的没有给出。

正确性

- 正确性:

- 技术原理、功能、支持平台、参数类型、异常报错等描述和软件实现不一致。

- 原理图、架构图等存在错误。

- 命令、命令参数等错误。

- 代码片段错误。

- 命令无法完成对应功能。

- 界面错误,无法指导操作。

- 代码样例运行报错、运行结果不符。

风险提示

- 风险提示:

- 对重要数据或系统存在风险的操作,缺少安全提示。

内容合规

- 内容合规:

- 违反法律法规,涉及政治、领土主权等敏感词。

- 内容侵权。

请选择问题类型

问题描述

点击输入详细问题描述,以帮助我们快速定位问题。

mindspore.ops.StridedSlice

class mindspore.ops.StridedSlice(begin_mask=0, end_mask=0, ellipsis_mask=0, new_axis_mask=0, shrink_axis_mask=0)[source]

Extracts a strided slice of a tensor.

Given an input tensor, this operation inserts a dimension of length 1 at the dimension. This operation extracts a fragment of size (end-begin)/stride from the given ‘input_tensor’. Starting from the beginning position, the fragment continues adding stride to the index until all dimensions are not less than the ending position.

Given a input_x[m1, m2, …, mn], begin, end and strides will be vectors of length n.

In each mask field (begin_mask, end_mask, ellipsis_mask, new_axis_mask, shrink_axis_mask) the ith bit will correspond to the ith m.

If the ith bit of begin_mask is set, begin[i] is ignored and the fullest possible range in that dimension is used instead. end_mask is analogous, except with the end range.

As for a 5*6*7 tensor, x[2:,:3,:] is equivalent to x[2:5,0:3,0:7].

If the ith bit of ellipsis_mask is set, as many unspecified dimensions as needed will be inserted between other dimensions. Only one non-zero bit is allowed in ellipsis_mask.

As for a 5*6*7*8 tensor, x[2:,…,:6] is equivalent to x[2:5,:,:,0:6]. x[2:,…] is equivalent to x[2:5,:,:,:].

If the ith bit of new_axis_mask is set, begin, end and strides are ignored and a new length 1 dimension is added at the specified position in tthe output tensor.

As for a 5*6*7 tensor, x[:2, newaxis, :6] will produce a tensor with shape (2, 1, 7).

If the ith bit of shrink_axis_mask is set, ith size shrinks the dimension by 1, taking on the value at index begin[i], end[i] and strides[i] are ignored.

As for a 5*6*7 tensor, x[:, 5, :] will result in shrink_axis_mask equal to 4.

Note

The stride may be negative value, which causes reverse slicing. The shape of begin, end and strides must be the same. begin and end are zero-indexed. The element of strides must be non-zero.

Parameters
  • begin_mask (int) – Starting index of the slice. Default: 0.

  • end_mask (int) – Ending index of the slice. Default: 0.

  • ellipsis_mask (int) – An int mask. Default: 0.

  • new_axis_mask (int) – An int mask. Default: 0.

  • shrink_axis_mask (int) – An int mask. Default: 0.

Inputs:
  • input_x (Tensor) - The input Tensor.

  • begin (tuple[int]) - A tuple which represents the location where to start. Only constant value is allowed.

  • end (tuple[int]) - A tuple or which represents the maximum location where to end. Only constant value is allowed.

  • strides (tuple[int]) - A tuple which represents the stride is continuously added before reaching the maximum location. Only constant value is allowed.

Outputs:

Tensor, The output is explained by following example.

In the 0th dimension, begin is 1, end is 2, and strides is 1, because 1+1=22, the interval is [1,2). Thus, return the element with index=1 in 0th dimension, i.e., [[3, 3, 3], [4, 4, 4]].

In the 1st dimension, similarly, the interval is [0,1). Based on the return value of the 0th dimension, return the element with index=0, i.e., [3, 3, 3].

In the 2nd dimension, similarly, the interval is [0,3). Based on the return value of the 1st dimension, return the element with index=0,1,2, i.e., [3, 3, 3].

Finally, the output is [3, 3, 3].

Raises
  • TypeError – If begin_mask, end_mask, ellipsis_mask, new_axis_mask or shrink_axis_mask is not an int.

  • TypeError – If begin, end or strides is not a tuple.

  • ValueError – If begin_mask, end_mask, ellipsis_mask, new_axis_mask or shrink_axis_mask is less than 0.

Supported Platforms:

Ascend GPU CPU

Examples

>>> 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.]]]