【发布时间】:2023-02-04 04:50:03
【问题描述】:
我有一个看起来像这样的张量:
tensor([[-0.0150, 0.1234],
[-0.0184, 0.1062],
[-0.0139, 0.1113],
[-0.0088, 0.0726]])
另一个看起来像这样:
tensor([[1.],
[1.],
[0.],
[0.]])
我想为每一行返回第一个张量的值,这些值对应于第二个张量的索引。
所以我们的输出将是:
tensor([0.1234], [0.1062], [-0.0139], [-0.0088]])
到目前为止我有这段代码:
return torch.gather(tensor1, tensor2)
但是我收到错误:
TypeError: gather() received an invalid combination of arguments - got (Tensor, Tensor), but expected one of:
* (Tensor input, int dim, Tensor index, *, bool sparse_grad, Tensor out)
* (Tensor input, name dim, Tensor index, *, bool sparse_grad, Tensor out)
我究竟做错了什么?
【问题讨论】: