mindspore.ops.narrow

查看源文件
mindspore.ops.narrow(input, axis, start, length)[源代码]

沿指定轴 axis ,从 start 位置截取长度为 length 的tensor。

参数:
  • input (Tensor) - 输入tensor。

  • axis (int) - 指定的轴。

  • start (int) - 指定起始位置。

  • length (int) - 指定长度。

返回:

Tensor

支持平台:

Ascend GPU CPU

样例:

>>> import mindspore
>>> x = mindspore.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], mindspore.int32)
>>> output = mindspore.ops.narrow(x, 0, 0, 2)
>>> print(output)
[[ 1 2 3]
 [ 4 5 6]]
>>> output = mindspore.ops.narrow(x, 1, 1, 2)
>>> print(output)
[[ 2 3]
 [ 5 6]
 [ 8 9]]