仔细看了PyTorch的文档才搞懂这两个函数
PyTorch: torch.Tensor.scatter
另一个文档: pytorch_scatter
scatter()
这个是scatter_()的out-of-place版本,即函数修改的不是原tensor
在vscode里面看这个函数有两种:
scatter(self: Tensor, dim: _int, index: Tensor, src: Tensor) -> Tensor
# param dim:_int 是让输入第一个参数(?
scatter(self: Tensor, dim: _int, index: Tensor, value: Number) -> Tensor
# param dim:_int
两个的区别在于最后一个参数,可以用Tensor作为src进行填充,也可以指定某个数值作为填充
scatter_()
一句话总结:在一个tensor的基础上,在dim
维上,根据index
选择src
的一些数填到原始的那个tensor里。
对于scatter,向原始tensor填数得到另外一个tensor