評價此頁

torch.select_scatter#

torch.select_scatter(input, src, dim, index) Tensor#

src 張量的值嵌入到給定索引的 input 中。此函式返回一個具有新儲存的張量,它不建立檢視。

引數
  • input (Tensor) – 輸入張量。

  • src (Tensor) – 要嵌入到 input 中的張量

  • dim (int) – 要將切片插入到的維度。

  • index (int) – 用於選擇的索引

注意

src 的大小必須適合嵌入到 input 中。具體來說,它應該與 torch.select(input, dim, index) 的形狀相同。

示例

>>> a = torch.zeros(2, 2)
>>> b = torch.ones(2)
>>> a.select_scatter(b, 0, 0)
tensor([[1., 1.],
        [0., 0.]])