mindspore.ops.narrow

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

Obtains a tensor of a specified length at a specified start position along a specified axis.

Parameters
  • input (Tensor) – the tensor to narrow.

  • axis (int) – the axis along which to narrow.

  • start (int) – the starting dimension.

  • length (int) – the distance to the ending dimension.

Returns

Tensor.

  • output (Tensors) - The narrowed tensor.

Raises

TypeError – If the input is not a tensor or tuple or list of tensors.

Supported Platforms:

Ascend GPU CPU

Examples

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