好久没更新博客了,最近一直在忙,既有生活上的也有工作上的。道阻且长啊。
今天来水一文,说一说最近工作上遇到的一个函数:torch.gather() 。...Pytorch 的官方文档的写法其实也是这个意思,但是看这么多个方括号可能会有点懵:
out[i][j][k] = input[index[i][j][k]][j][k] # if dim == 0...[2, 2, 2, 2]],
[[0, 0, 0, 0],
[2, 2, 2, 2]]])
简单可描述如下图:
为描述方便,假如我们把输入看作是...如果输出和输入一样,那么原本的 index_tensor 就是如下:
tensor([[[0, 0, 0, 0],
[1, 1, 1, 1],
[2, 2, 2, 2...Reference
torch.gather — PyTorch 1.9.0 documentation
numpy.take — NumPy v1.21 Manual
tf.gather | TensorFlow