mindspore.mint.narrow

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

Returns a narrowed tensor from input tensor, and the dimension axis is input from start to start + length.

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

  • dim (int) – dimension along which to narrow.

  • start (int) – the starting dimension.

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

Returns

Tensor.

Raises
  • ValueError – If dim is out of range [-input.ndim, input.ndim).

  • ValueError – If start is out of range [-input.shape[dim], input.shape[dim]].

  • ValueError – It length is out of range [0, input.shape[dim]-start].

Supported Platforms:

Ascend

Examples

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