torch.slice_scatter¶
- torch.slice_scatter(input, src, dim=0, start=None, end=None, step=1) Tensor ¶
将
src
张量的值嵌入到input
中指定的维度。此函数返回一个新的存储空间的张量;它不会创建一个视图。- 参数:
input (Tensor) – 输入张量。
src (张量) – 要嵌入到
input
中的张量。dim(int)- 插入切片的维度
start(可选[int])- 插入切片的起始索引
end(可选[int])- 插入切片的结束索引
step(int)- 跳过的元素数量
示例:
>>> a = torch.zeros(8, 8) >>> b = torch.ones(2, 8) >>> a.slice_scatter(b, start=6) tensor([[0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0.], [1., 1., 1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1., 1., 1.]]) >>> b = torch.ones(8, 2) >>> a.slice_scatter(b, dim=1, start=2, end=6, step=2) tensor([[0., 0., 1., 0., 1., 0., 0., 0.], [0., 0., 1., 0., 1., 0., 0., 0.], [0., 0., 1., 0., 1., 0., 0., 0.], [0., 0., 1., 0., 1., 0., 0., 0.], [0., 0., 1., 0., 1., 0., 0., 0.], [0., 0., 1., 0., 1., 0., 0., 0.], [0., 0., 1., 0., 1., 0., 0., 0.], [0., 0., 1., 0., 1., 0., 0., 0.]])