遇到了用tensor来index另外一个tensor的操作,在Pytorch中右2个比较相似的操作
torch.index_select 和 torch.
gather
torch.
index_select
(input, dim, index, out=None) → Tensor
Returns a new tensor which indexes the input
tensor along dimension dim
using the entries in index
which is a LongTensor.
The returned tensor has the same number of dimensions as the original tensor (input
). The dim
th dimension has the same size as the length of index
; other dimensions have the same size as in the original tensor. (输出tensor的指定dim的维度是index的长度,其他维度不变)
NOTE
The returned tensor does not use the same storage as the original tensor. If out
has a different shape than ex