PyTorch张量的加权平均

9
我有两个形式为[y11,y12]和[y21,y22]的Pytorch张量。如何得到这两个张量的加权平均值?
1个回答

8

您可以使用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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接