【问题标题】:Weighted Average of PyTorch TensorsPyTorch 张量的加权平均值
【发布时间】:2020-11-17 13:41:17
【问题描述】:

我有两个 [y11, y12] 和 [y21, y22] 形式的 Pytorch 张量。如何获得两个张量的加权平均值?

【问题讨论】:

    标签: python numpy pytorch tensor weighted-average


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2017-06-19
      • 2021-01-10
      • 2021-11-21
      • 2022-01-26
      • 1970-01-01
      • 1970-01-01
      • 2016-12-08
      • 2016-05-23
      • 1970-01-01
      相关资源
      最近更新 更多