【问题标题】:Pytorch: Differentiable countingPytorch:可微分计数
【发布时间】:2020-07-08 14:12:10
【问题描述】:

我需要计算张量中满足某个条件的元素的数量,例如计算年龄 == 60 或年龄 >= 50 的人数。计数函数是否存在可微近似?

【问题讨论】:

    标签: pytorch mathematical-optimization


    【解决方案1】:

    age >= 50 返回的布尔张量上使用torch.Tensor.sumtorch.sum

    age = torch.arange(75)
    
    (age >= 50).sum()
    tensor(25)
    

    【讨论】:

      猜你喜欢
      • 2022-11-09
      • 1970-01-01
      • 2020-07-22
      • 2018-12-05
      • 1970-01-01
      • 2021-10-08
      • 2020-12-30
      • 2021-12-13
      • 2020-04-28
      相关资源
      最近更新 更多