output.eq()函数解读

发布时间:2026/7/28 14:49:02
output.eq()函数解读 函数作用比较a和b两个数据类型的相同的地方相同为1不同为0注意两个数据类型ab必须要size相同。代码 ctorch.tensor([[1,2],[3,4],[5,6]]) dtorch.tensor([[1,1],[2,4],[0,0]]) print(c:, c,d:, d) c: tensor([[1, 2], [3, 4], [5, 6]]) d: tensor([[1, 1], [2, 4], [0, 0]]) ac.eq(d) print(a) tensor([[1, 0], [0, 1], [0, 0]], dtypetorch.uint8)获得相同的个数 a.view(-1).float().sum(0) tensor(2.)即cd中相同的元素个数为2。