我有两个形式为[y11,y12]和[y21,y22]的Pytorch张量。如何得到这两个张量的加权平均值?
您可以使用torch.add
添加两个张量,然后使用torch.mean
获取输出张量的平均值。假设张量1的权重为0.6,张量2的权重为0.4。例如:
tensor1 = [y11, y12] * 0.6 # multiplying with weight
tensor2 = [y21, y22] * 0.4 # multiplying with weight
pt_addition_result_ex = tensor1.add(tensor2) # addition of two tensors
torch.mean(pt_addition_result_ex) # mean of output tensors