不用循环,用 pytorch 的基本函数, 非常简洁. 代码如下:
import torch
x = torch.tensor([[1, 2], [3, 4]])
y = torch.tensor([[1, 2], [3, 4]])
assert 0 == ((x != y).sum())
xx = torch.tensor([[1, 2], [3, 4]])
yy = torch.tensor([[2, 2], [3, 3]])
assert 0 == (xx != yy).sum()
不用循环,用 pytorch 的基本函数, 非常简洁. 代码如下:
import torch
x = torch.tensor([[1, 2], [3, 4]])
y = torch.tensor([[1, 2], [3, 4]])
assert 0 == ((x != y).sum())
xx = torch.tensor([[1, 2], [3, 4]])
yy = torch.tensor([[2, 2], [3, 3]])
assert 0 == (xx != yy).sum()
本文标题:pytorch 判断两个 tensor 是否相等
本文链接:https://www.haomeiwen.com/subject/tydeuktx.html
网友评论