mindspore.ops.narrow

View Source On Gitee
mindspore.ops.narrow(input, axis, start, length)[source]

Slice the tensor from the start position with a length of length along axis .

Parameters
  • input (Tensor) – The input tensor.

  • axis (int) – the specified axis.

  • start (int) – the specified starting position.

  • length (int) – the specified length.

Returns

Tensor

Supported Platforms:

Ascend GPU CPU

Examples

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