【发布时间】:2020-11-17 13:41:17
【问题描述】:
我有两个 [y11, y12] 和 [y21, y22] 形式的 Pytorch 张量。如何获得两个张量的加权平均值?
【问题讨论】:
标签: python numpy pytorch tensor weighted-average
我有两个 [y11, y12] 和 [y21, y22] 形式的 Pytorch 张量。如何获得两个张量的加权平均值?
【问题讨论】:
标签: python numpy pytorch tensor weighted-average
您可以使用torch.add 添加两个张量,然后使用torch.mean 获得输出张量的平均值
假设 tensor1 的权重为 0.6,tensor2 的权重为 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
【讨论】: