参考torch.eq、torch.ne、torch.gt、torch.lt、torch.ge、torch.le - 云+社区 - 腾讯云
PyTorch - torch.eq、torch.ne、torch.gt、torch.lt、torch.ge、torch.le
flyfish
torch.eq、torch.ne、torch.gt、torch.lt、torch.ge、torch.le
以上全是简写
参数是input, other, out=None
逐元素比较input和other
返回是torch.BoolTensor
import torch
a=torch.tensor([[1, 2], [3, 4]])
b=torch.tensor([[1, 2], [4, 3]])
print(torch.eq(a,b))#equals
# tensor([[ True, True],
# [False, False]])
print(torch.ne(a,b))#not equal to
# tensor([[False, False],
# [ True, True]])
print(torch.gt(a,b))#greater than
# tensor([[False, False],
# [False, True]])
print(torch.lt(a,b))#less than
# tensor([[False, False],
# [ True, False]])
print(torch.ge(a,b))#greater than or equal to
# tensor([[ True, True],
# [False, True]])
print(torch.le(a,b))#less than or equal to
# tensor([[ True, True],
# [ True, False]])
这篇博客介绍了PyTorch中用于元素比较的几个函数,如torch.eq、torch.ne、torch.gt、torch.lt、torch.ge和torch.le,通过示例展示了它们如何在张量之间进行逐元素比较并返回布尔张量。这些函数对于张量运算和条件判断非常有用。
13万+

被折叠的 条评论
为什么被折叠?



