torch_npu.npu_slice

API接口

torch_npu.npu_slice(self, offsets, size) -> Tensor

功能描述

从张量中提取切片。

参数说明

示例

>>> input = torch.tensor([[1,2,3,4,5], [6,7,8,9,10]], dtype=torch.float16).to("npu")
>>> offsets = [0, 0]>>> size = [2, 2]
>>> output = torch_npu.npu_slice(input, offsets, size)
>>> output
tensor([[1., 2.],
        [6., 7.]], device='npu:0', dtype=torch.float16)