复制Pytorch中某些索引的张量元素
所需的操作在精神上与torch.tensor.index_copy
相似,但有些不同。
最好用一个例子来解释。
张量a
具有我们将复制的原始值:
[10,20,30]
张量b
具有a :
[0、1、0、1、2、1]
张量c
的长度与b
,包含<索引值<代码> a :
[10、20、10、20、30、20]
是从a c
的好方法>和b
在pytorch中,不使用循环?
The desired operation is similar in spirit to torch.Tensor.index_copy
, but a little different.
It's best explained with an example.
Tensor A
has original values that we will copy:
[10, 20, 30]
Tensor B
has indices of A
:
[0, 1, 0, 1, 2, 1]
Tensor C
has same length as B
, containing the indexed values of A
:
[10, 20, 10, 20, 30, 20]
What's a good way to make C
from A
and B
in PyTorch, without using loops?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过仅通过A索引?
Have you tried just indexing by A?