mindspore.Tensor.narrow
- Tensor.narrow(dim, start, length) Tensor[source]
- Obtains a tensor of a specified length at a specified start position along a specified axis. - Parameters
- Returns
- output (Tensors) - The narrowed tensor. 
- Raises
- ValueError – The value of dim is out of range [-self.ndim, self.ndim). 
- ValueError – The value of start is out of range [-self.shape[dim], self.shape[dim]]. 
- ValueError – The value of length is out of range [0, self.shape[dim] - start]. 
 
 - Supported Platforms:
- Ascend- GPU- CPU
 - Examples - >>> import mindspore >>> from mindspore import Tensor >>> x = Tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], mindspore.int32) >>> output = x.narrow(0, 0, 2) >>> print(output) [[ 1 2 3] [ 4 5 6]] >>> output = x.narrow(1, 1, 2) >>> print(output) [[ 2 3] [ 5 6] [ 8 9]]