映射TORCH的每个元素。 plupsose i有一个张量,只有零和一个: t = torch.tensor([1,0,0,1]) 和一个重量的dict: 权重= {0:0.1,1:0.9} 我想形成一个新的张量new_t,以便每个e ...

问题描述 投票:0回答:0

t = torch.Tensor([1, 0, 0, 1])


和the the the dict:

weights

我想形成一个新的张量
weights = {0: 0.1, 1: 0.9}

,以便张量中的每个元素都映射到dict

new_t

中的相应值。

t
有一种优雅的方法可以做到这一点,而无需迭代张量吗?我听说过
weights
,但是只有在CPU上张紧tensor

new_t = torch.Tensor([0.9, 0.1, 0.1, 0.9])

,还有其他选择吗?

    

如果您将重量转换为张量,则可以直接索引

t
    

python dictionary pytorch mapping tensor
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.